Skip to content

Commit a0e8a18

Browse files
mp3: add detection of large fills of invalid bytes mid stream
1 parent 98e9d72 commit a0e8a18

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

plugins/mp3/mp3parser.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ mp3_parse_file (mp3info_t *info, uint32_t flags, DB_FILE *fp, int64_t fsize, int
440440

441441
int64_t offs = startoffs;
442442
int64_t fileoffs = startoffs;
443+
int64_t lastpacketoffs = -1;
443444

444445
int prev_br = -1;
445446
int prev_length = -1;
@@ -489,6 +490,13 @@ mp3_parse_file (mp3info_t *info, uint32_t flags, DB_FILE *fp, int64_t fsize, int
489490
goto error;
490491
}
491492

493+
// if there are valid packets, but there's a large fill of invalid data -- assume EOF,
494+
// otherwise this may hang for a very long time.
495+
// Example scenario: 150MB mp3 file filled with zeroes in 2nd half.
496+
if (lastpacketoffs != -1 && offs - lastpacketoffs > MAX_INVALID_BYTES) {
497+
goto end;
498+
}
499+
492500
// prevent misdetected garbage packets to be used as ref_packet
493501
if (info->npackets == 1) {
494502
info->npackets = 0;
@@ -517,6 +525,7 @@ mp3_parse_file (mp3info_t *info, uint32_t flags, DB_FILE *fp, int64_t fsize, int
517525
}
518526

519527
packet.offs = offs;
528+
lastpacketoffs = offs;
520529

521530
if (!info->packet_offs || seek_to_sample >= 0) {
522531
info->packet_offs = offs;

0 commit comments

Comments
 (0)