@@ -3018,23 +3018,27 @@ static drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drm
30183018 ((drmp3_uint32 )ape [26 ] << 16 ) |
30193019 ((drmp3_uint32 )ape [27 ] << 24 );
30203020
3021- streamEndOffset -= 32 + tagSize ;
3022- streamLen -= 32 + tagSize ;
3023-
3024- /* Fire a metadata callback for the APE data. Must include both the main content and footer. */
3025- if (onMeta != NULL ) {
3026- /* We first need to seek to the start of the APE tag. */
3027- if (onSeek (pUserData , streamEndOffset , DRMP3_SEEK_END )) {
3028- size_t apeTagSize = (size_t )tagSize + 32 ;
3029- drmp3_uint8 * pTagData = (drmp3_uint8 * )drmp3_malloc (apeTagSize , pAllocationCallbacks );
3030- if (pTagData != NULL ) {
3031- if (onRead (pUserData , pTagData , apeTagSize ) == apeTagSize ) {
3032- drmp3__on_meta (pMP3 , DRMP3_METADATA_TYPE_APE , pTagData , apeTagSize );
3021+ if (32 + tagSize < streamLen ) {
3022+ streamEndOffset -= 32 + tagSize ;
3023+ streamLen -= 32 + tagSize ;
3024+
3025+ /* Fire a metadata callback for the APE data. Must include both the main content and footer. */
3026+ if (onMeta != NULL ) {
3027+ /* We first need to seek to the start of the APE tag. */
3028+ if (onSeek (pUserData , streamEndOffset , DRMP3_SEEK_END )) {
3029+ size_t apeTagSize = (size_t )tagSize + 32 ;
3030+ drmp3_uint8 * pTagData = (drmp3_uint8 * )drmp3_malloc (apeTagSize , pAllocationCallbacks );
3031+ if (pTagData != NULL ) {
3032+ if (onRead (pUserData , pTagData , apeTagSize ) == apeTagSize ) {
3033+ drmp3__on_meta (pMP3 , DRMP3_METADATA_TYPE_APE , pTagData , apeTagSize );
3034+ }
3035+
3036+ drmp3_free (pTagData , pAllocationCallbacks );
30333037 }
3034-
3035- drmp3_free (pTagData , pAllocationCallbacks );
30363038 }
30373039 }
3040+ } else {
3041+ /* The tag size is larger than the stream. Invalid APE tag. */
30383042 }
30393043 }
30403044 }
@@ -5004,6 +5008,7 @@ REVISION HISTORY
50045008v0.7.2 - TBD
50055009 - Reduce stack space to improve robustness on embedded systems.
50065010 - Fix a compilation error with MSVC Clang toolset relating to cpuid.
5011+ - Fix an error with APE tag parsing.
50075012
50085013v0.7.1 - 2025-09-10
50095014 - Silence a warning with GCC.
0 commit comments