From 04ecb3c645c7c57976e7bd4cc096b78dbd52d106 Mon Sep 17 00:00:00 2001 From: Michael Giacomelli Date: Sat, 19 Sep 2026 16:07:28 -0400 Subject: [PATCH] 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 --- lib/rbcodec/codecs/flac.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/rbcodec/codecs/flac.c b/lib/rbcodec/codecs/flac.c index 00d4dd71ca..dc3c4ba06f 100644 --- a/lib/rbcodec/codecs/flac.c +++ b/lib/rbcodec/codecs/flac.c @@ -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;