flac: don't divide by zero when STREAMINFO has no sample count

A total sample count of 0 means unknown. It made the track length 0 and the
bitrate estimate in flac_init() divided by it, crashing the codec (FLAC
decoder testbench file 45). Report a bitrate of 0 in that case.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Michael Giacomelli 2026-09-19 16:07:28 -04:00 • committed by Michael
parent a81fd7b77f
commit 04ecb3c645

View file

@ -209,8 +209,9 @@ static bool flac_init(FLACContext* fc, int first_frame_offset)
}
if (found_streaminfo) {
fc->bitrate = ((int64_t) (fc->filesize-fc->metadatalength) * 8)
/ fc->length;
/* length is 0 when STREAMINFO has no total sample count */
fc->bitrate = fc->length ? ((int64_t) (fc->filesize-fc->metadatalength) * 8)
/ fc->length : 0;
return true;
} else {
return false;