From 110e991c3a66335d8fc987cc638707145ab5afa9 Mon Sep 17 00:00:00 2001 From: Autumn Ashton Date: Fri, 27 Jun 2025 03:37:53 -0700 Subject: [PATCH] minimp3: Support for MP3 files < MAX_FRAME_SYNC_MATCHES Signed-off-by: Christopher Snowhill --- .../vgmstream/src/coding/libs/minimp3.h | 17 +++++++++++++++++ Plugins/minimp3/ThirdParty/minimp3.h | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Frameworks/vgmstream/vgmstream/src/coding/libs/minimp3.h b/Frameworks/vgmstream/vgmstream/src/coding/libs/minimp3.h index 4a46f3cb0..ed25aca97 100644 --- a/Frameworks/vgmstream/vgmstream/src/coding/libs/minimp3.h +++ b/Frameworks/vgmstream/vgmstream/src/coding/libs/minimp3.h @@ -1654,6 +1654,21 @@ static void mp3d_synth_granule(float *qmf_state, float *grbuf, int nbands, int n } } +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; @@ -1662,6 +1677,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; } diff --git a/Plugins/minimp3/ThirdParty/minimp3.h b/Plugins/minimp3/ThirdParty/minimp3.h index 4a46f3cb0..ed25aca97 100644 --- a/Plugins/minimp3/ThirdParty/minimp3.h +++ b/Plugins/minimp3/ThirdParty/minimp3.h @@ -1654,6 +1654,21 @@ static void mp3d_synth_granule(float *qmf_state, float *grbuf, int nbands, int n } } +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; @@ -1662,6 +1677,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; }