From dc536eef3d835ff51caeb83903b028a9726a6bb4 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Fri, 15 Jul 2022 22:51:04 -0700 Subject: [PATCH] [MAD Decoder] Don't crash on bad files The local and seekable file scanner could crash on bad MPEG files if they failed to decode any frames and broke due to either end of file or other unrecoverable errors, due to a division by zero error attempting to calculate the file bitrate. Now correctly return error state if this occurs, bailing early. Signed-off-by: Christopher Snowhill --- Plugins/MAD/MADDecoder.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Plugins/MAD/MADDecoder.m b/Plugins/MAD/MADDecoder.m index b0a3d1cdd..90d0ba53f 100644 --- a/Plugins/MAD/MADDecoder.m +++ b/Plugins/MAD/MADDecoder.m @@ -406,6 +406,11 @@ } } + // Don't commit division by zero on bad files + if(stream.next_frame == stream.this_frame) { + return NO; + } + if(!_foundiTunSMPB && !_foundXingHeader && !_foundVBRIHeader) { // Now do CBR estimation instead of full file scanning size_t frameCount = (_fileSize - id3_length) / (stream.next_frame - stream.this_frame);