<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">It seems that the bitstream reader is not working as it should (verified in version 1.2.0 and 1.2.1).<div>The problem is as follows: if the data read by the read callback is not a multiple of 4, the bit reader will end up in a very bad state, where the bits_consumed field will grow without ever being reset to 0, and that causes everything to fail.</div><div>This is not a case that's encountered very often, because in general (like for example when reading from a file), the read callback will return as many bytes as were asked for, which happens to be a multiple of 4. But when reading from a network socket, or some type of buffering code, it can happen that reads are shorter than requested, and not always multiples of 4, and that produces decoding problems.</div><div>The problem is very easy to reproduce: in the read callback, always return 1 byte, regardless of how many bytes are asked for.</div><div>For example, in a typical read callback routine, one can do the (simplified) following and see the problem:</div><div><br></div><div><div><font class="Apple-style-span" face="'Courier New'">static FLAC__StreamDecoderReadStatus&nbsp;</font></div><div><font class="Apple-style-span" face="'Courier New'">FlacDecoder_ReadCallback(const FLAC__StreamDecoder* flac,&nbsp;</font></div><div><font class="Apple-style-span" face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FLAC__byte &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[],&nbsp;</font></div><div><font class="Apple-style-span" face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; size_t*&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bytes,&nbsp;</font></div><div><font class="Apple-style-span" face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; void*&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client_data)</font></div><div><font class="Apple-style-span" face="'Courier New'">{</font></div><div><font class="Apple-style-span" face="'Courier New'">&nbsp;&nbsp; &nbsp;*bytes=1; &nbsp; /* &lt;--- this was added to always return at most one byte */</font></div><div><font class="Apple-style-span" face="'Courier New'">&nbsp;&nbsp; &nbsp;read_only_one_byte_into_buffer(buffer);</font></div><div><font class="Apple-style-span" face="'Courier New'">&nbsp; &nbsp; return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;</font></div><div><font class="Apple-style-span" face="'Courier New'">}</font></div><br></div><div><br></div><div>Any hints on how to get this fixed?</div><div><br></div><div>-- Gilles</div></body></html>