Repository navigation
Conversation
`FLAC__metadata_simple_iterator_init()` sets `iterator->has_stats` only when the file is opened with `read_only == false` and `preserve_file_stats == true`; otherwise it leaves the previous value. When an iterator that was first initialized on file A with `preserve_file_stats` is initialized again on file B (read-only, or without `preserve_file_stats`), `has_stats` is still true and `stats` still holds A's attributes. When B is closed (`FLAC__metadata_simple_iterator_delete()` or the next `init()`), `simple_iterator_free_guts_()` calls `set_file_stats_()` on B: B gets A's permissions, modification time and owner/group.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FLAC__metadata_simple_iterator_init()setsiterator->has_statsonly when the file is opened withread_only == falseandpreserve_file_stats == true; otherwise it leaves the previous value. When an iterator that was first initialized on file A withpreserve_file_statsis initialized again on file B (read-only, or withoutpreserve_file_stats),has_statsis still true andstatsstill holds A's attributes. When B is closed (FLAC__metadata_simple_iterator_delete()or the nextinit()),simple_iterator_free_guts_()callsset_file_stats_()on B: B gets A's permissions, modification time and owner/group.init()already handles being called on a used iterator: it starts withsimple_iterator_free_guts_(), which closes the previous file and restores that file's attributes. The header documentspreserve_file_statsas keeping the owner and modification time of the file being edited; a read-only walk over B should not change B at all.Reproduction
Tested on master 59fa340. The program
metareuse.cin https://gist.github.com/GeekQAQ/4a3ebaafe40342e6c035c086f93c1916 (withflac_common.h) writes a.flac (mode 0644, mtime 1000000000) and b.flac (mode 0600, mtime 1200000000) to a temporary directory:The second
init(b, read_only=false, preserve_file_stats=false)behaves the same (reuse-writable). If the firstinit()did not ask to preserve the attributes there is no difference (reuse-nopreserve).Change
Clear
has_statsininit()right aftersimple_iterator_free_guts_(), before it is set again for this file. With the change, b.flac keeps mode 0600 and its mtime in all modes.test_libFLACpasses (ctestlibFLAC, ASan+UBSan build).