#316 assertion failed in bitreader.c

1.3.0
open-works-for-me
Erik
libFLAC (57)
5
2014-03-21
2007-12-02
Anonymous
No

In libFLAC 1.2.1 , if the stream decoder callback does not fill completely the supplied buffer, then a sync error is quickly reported by flac. If compiled with --enable-debug, I get an "../../../src/libFLAC/bitreader.c:1074: failed assertion `cbits < 32'"

Bug can be reproduced easily by patch test_libFLAC:

static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
{
StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
- const size_t requested_bytes = *bytes;
+ size_t requested_bytes = *bytes;
+
+ if (requested_bytes > 3 && (rand() % 3)==0)
+ requested_bytes = requested_bytes/3;

(void)decoder;

I am transitionning from flac 1.1.2, so the only thing I am sure is that it used to work in 1.1.2

Platform is Darwin, configure option are:
../configure --with-pic --disable-ogg --disable-asm-optimizations --enable-debug

--
Julien ( hules@free.fr )

Discussion

  • Josh Coalson
    Josh Coalson
    2007-12-02

    • assigned_to: nobody --> jcoalson
     
  • Richard Nixon
    Richard Nixon
    2008-06-19

    Logged In: YES
    user_id=2123080
    Originator: NO

    I'm not an expert on flac by any means but looking logically at what FLAC__bitreader_read_rice_signed_block() is trying to do when dealing with trailing bytes shouldn't the code read something like ...

                else \{
                    uval += end - cbits;
    

    >>> cbits = end;
    FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
    /* didn't find stop bit yet, have to keep going... */
    }

    ... when this state occurs should cbits either be set to 'end' or 0 rather than 'cbits += end'.

    I have to confess I've got little idea about what on earth this function is doing though.

     
  • Richard Nixon
    Richard Nixon
    2008-06-19

    Logged In: YES
    user_id=2123080
    Originator: NO

    I should have said in my previous comment that I've tried both 0 and 'end' (in the non-_MSC_VER version). Both values make the assertion disappear and the music still sounds the same for both. Mmmm.

     
  • Richard Nixon
    Richard Nixon
    2008-06-19

    Logged In: YES
    user_id=2123080
    Originator: NO

    I should have said in my previous comment that I've tried both 0 and 'end' (in the non-_MSC_VER version). Both values make the assertion disappear and the music still sounds the same for both. Mmmm.

     
  • Erik
    Erik
    2014-03-21

    • status: open --> open-works-for-me
    • assigned_to: Josh Coalson --> Erik
    • Group: --> 1.3.0
     
  • Erik
    Erik
    2014-03-21

    Is this still a problem?