Problem decoding some Flac files



I am working on a program for analyzing sound level, dynamics and clipping in any music library.
For this I am using the FlacBox code.

However, I receive a few types of FlacExceptions when reading certain flac files:

The files were ripped using a recent version of dbPoweramp (, and I ran over 10000 files, and around 50 failed with the following errors.

Exception:FlacBox.FlacException: Invalid subframe coefficient precision
Exception:FlacBox.FlacException: Subframe type is set to reserved=17
Exception:FlacBox.FlacException: Subframe type is set to reserved=18
Exception:FlacBox.FlacException: Subframe type is set to reserved=4
Exception:FlacBox.FlacException: Unexpected end of stream: bit reader needs data
Exception:FlacBox.FlacException: Zeros expected for alignment padding

I have tried re-ripping most of the files in dbPoweramp, but the results are the same.

After some debugging I have found that the problem lies in FlacReader.cpp line 290, where this line:

int subframeBitsPerSample = FrameBitsPerSample;

should be replaced by these lines:

int subframeBitsPerSample;
if (type == SubframeType.SubframeConstant)
subframeBitsPerSample = FrameBitsPerSample - wastedBitsPerSample;
subframeBitsPerSample = FrameBitsPerSample;