Skip to content

Commit

Permalink
Support for short MP3 files
Browse files Browse the repository at this point in the history
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
  • Loading branch information
misyltoad committed Aug 9, 2024
1 parent 93f0373 commit f03fbce
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions minimp3.h
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,21 @@ static void mp3d_synth_granule( float* qmf_state, float* grbuf, int nbands, int
}
}

static int hdr_is_tag( const uint8_t *hdr )
{
return hdr[0] == 'T' && hdr[1] == 'A' && hdr[2] == 'G' && hdr[3] == '\0';
}

static int hdr_is_null( const uint8_t *hdr )
{
return hdr[0] == '\0' || hdr[1] == '\0' || hdr[2] == '\0' || hdr[3] == '\0';
}

static int hdr_is_null_or_tag( const uint8_t *hdr )
{
return hdr_is_tag( hdr ) > 0 || hdr_is_null( hdr ) > 0;
}

static int mp3d_match_frame( const uint8_t* hdr, int mp3_bytes, int frame_bytes )
{
int i, nmatch;
Expand All @@ -1684,6 +1699,8 @@ static int mp3d_match_frame( const uint8_t* hdr, int mp3_bytes, int frame_bytes
i += hdr_frame_bytes( hdr + i, frame_bytes ) + hdr_padding( hdr + i );
if ( i + HDR_SIZE > mp3_bytes )
return nmatch > 0;
if ( hdr_is_null_or_tag( hdr + i ) )
return nmatch > 0;
if ( !hdr_compare( hdr, hdr + i ) )
return 0;
}
Expand Down

0 comments on commit f03fbce

Please sign in to comment.