#351 creates broken files with total_samples_estimate > 36bit

libFLAC (59)
Tim Müller

If FLAC__stream_encoder_set_total_samples_estimate() is called with a total_samples value that takes up more than 36 bits (e.g. due to a wrong calculation or some other bug), libFLAC may write files which the flac command line tool will refuse to decode ("xyz.flac: ERROR: bits per sample is 32, must be 4-24").

The ultimate reason for this seems to be that the bitwriter function FLAC__bitwriter_write_raw_uint32() does not zero out unused bits in the input value, so these bits may later 'leak' into the bitstream into bits that weren't meant to be touched.

This is particularly unfortunate given that the samples value is only supposed to be a temporary estimate which will be overwritten later with the actual value if the output is seekable. When that happens, the 'leaked' bit is never touched though, so that wrong value never gets fixed up, leading to invalid/unexpected bits in the stream info header for the bits_per_sample field.

Arguably FLAC__stream_encoder_set_total_samples_estimate() should be changed to clamp or check its input if fixing up the bitwriter is not deemed necessary (or I was confused and there isn't a problem in the first place).


Version: libFLAC 1.2.1 (debian sid package, amd64)


  • Josh Coalson

    Josh Coalson - 2009-08-14
    • priority: 5 --> 9
    • assigned_to: nobody --> jcoalson
    • status: open --> open-accepted
  • Erik

    Erik - 2016-01-08
    • status: open-accepted --> closed-fixed
    • Group: --> 1.3.0
  • Erik

    Erik - 2016-01-08

    FIxed in:

    commit 262505bd90a528c7add0bdade9afba132be8b1fc
    Author: Erik de Castro Lopo <erikd@mega-nerd.com>
    Date:   Sat Jan 9 10:46:41 2016 +1100
    libFLAC: Fix total_samples_estimate
    See the SF ticket for details.
    Patch-from: lvqcl <lvqcl.mail@gmail.com>
    Closes: https://sourceforge.net/p/flac/bugs/351/

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks