Skip to content

Commit f03fbce

Browse files
committed
Support for short MP3 files
If we match > 1 frame, and the next frame header is all NULL or a TAG then say that we matched a frame, as we likely reached the end of the file. lieff/minimp3#125
1 parent 93f0373 commit f03fbce

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

minimp3.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,21 @@ static void mp3d_synth_granule( float* qmf_state, float* grbuf, int nbands, int
16761676
}
16771677
}
16781678

1679+
static int hdr_is_tag( const uint8_t *hdr )
1680+
{
1681+
return hdr[0] == 'T' && hdr[1] == 'A' && hdr[2] == 'G' && hdr[3] == '\0';
1682+
}
1683+
1684+
static int hdr_is_null( const uint8_t *hdr )
1685+
{
1686+
return hdr[0] == '\0' || hdr[1] == '\0' || hdr[2] == '\0' || hdr[3] == '\0';
1687+
}
1688+
1689+
static int hdr_is_null_or_tag( const uint8_t *hdr )
1690+
{
1691+
return hdr_is_tag( hdr ) > 0 || hdr_is_null( hdr ) > 0;
1692+
}
1693+
16791694
static int mp3d_match_frame( const uint8_t* hdr, int mp3_bytes, int frame_bytes )
16801695
{
16811696
int i, nmatch;
@@ -1684,6 +1699,8 @@ static int mp3d_match_frame( const uint8_t* hdr, int mp3_bytes, int frame_bytes
16841699
i += hdr_frame_bytes( hdr + i, frame_bytes ) + hdr_padding( hdr + i );
16851700
if ( i + HDR_SIZE > mp3_bytes )
16861701
return nmatch > 0;
1702+
if ( hdr_is_null_or_tag( hdr + i ) )
1703+
return nmatch > 0;
16871704
if ( !hdr_compare( hdr, hdr + i ) )
16881705
return 0;
16891706
}

0 commit comments

Comments
 (0)