#362 Assertion failure after partial read

open
nobody
libFLAC (57)
5
2012-12-12
2010-03-05
Max Kellermann
No

When the "read" callback returns less than the requested number of bytes (e.g. always "1"), libFLAC may trigger an assertion failure inside FLAC__bitreader_read_rice_signed_block(), this is bitreader.c:1074 in flac-1.2.1.tar.gz.

Without --enable-debug, this leads to "sync lost" errors.

Problem is that the function miscalculates the number of bits which were already consumed, when only a few bytes (words==0) are available. When the stop bit is not present in these bytes, the code adds "end" to "cbits":

cbits += end;

This however *always* overflows the "cbits" variable if it was non-zero: "end" is the total number of bits available, and "cbits" is the number of those which were already consumed. "cbits+end" is beyond the defined data buffer. What was probably meant was a simple assignment, instead of an addition. Please verify the attached patch; I have just read your code base for the first time, I might be wrong.

Discussion

  • Max Kellermann
    Max Kellermann
    2010-03-05

    Proposed fix

     
    Attachments
  • Finally, this fixes the stuttering when playing FLACs with MPD via http!