Skip to content

libFLAC: rewind before flushing in FLAC__stream_decoder_reset() - #960

Open
GeekQAQ wants to merge 1 commit into
xiph:masterfrom
GeekQAQ:reset-rewind-first
Open

GeekQAQ wants to merge 1 commit into
xiph:masterfrom
GeekQAQ:reset-rewind-first

Conversation

@GeekQAQ

@GeekQAQ GeekQAQ commented Nov 24, 2026

Copy link
Copy Markdown

When the rewind in FLAC__stream_decoder_reset() fails (the seek callback returns FLAC__STREAM_DECODER_SEEK_STATUS_ERROR), the function should return false with the state unchanged, as documented in stream_decoder.h. It does return false, but it has already flushed the decoder and reset the Ogg layer by then: the buffered input is gone, the state has changed and MD5 checking is off.

This moves the rewind in front of the flush. Nothing else changes: an uninitialized decoder, or one in FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR, still fails without calling the seek callback, and the call from init still doesn't rewind.

Tested on master (59fa340), ASan+UBSan build, with the program from #958, seek callback failing once at the rewind:

after reset() returned false master this PR no reset() call
decode the rest of the stream 12 frames / 12772 samples, 1 error 20 frames / 21988 samples, no error 20 frames / 21988 samples, no error
state at the end of the stream SEARCH_FOR_FRAME_SYNC END_OF_STREAM END_OF_STREAM

The test suite (ctest, 10 tests) passes in the default, WITH_OGG=OFF, WITH_ASM=OFF, ENABLE_64_BIT_WORDS=OFF and FLAC__INTEGER_ONLY_LIBRARY builds.

Fixes #958

FLAC__stream_decoder_reset() is documented to leave the state unchanged
when the rewind fails, but it flushed the decoder and reset the Ogg layer
before calling the seek callback. After a failed reset, the buffered
input had been discarded, the state had changed and MD5 checking was off.

Fixes xiph#958
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FLAC__stream_decoder_reset(): a failed rewind has already flushed the decoder, contrary to "the state will be unchanged"

1 participant