Skip to content

Commit

Permalink
[MAD Decoder] Don't crash on bad files
Browse files Browse the repository at this point in the history
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 <kode54@gmail.com>
  • Loading branch information
kode54 committed Jul 16, 2022
1 parent 051b86c commit 804e765
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Plugins/MAD/MADDecoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ - (BOOL)scanFile {
}
}

// 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);
Expand Down

0 comments on commit 804e765

Please sign in to comment.