From 5a0aac8179e2ae4665e76c7c4f6ea89fe01145a7 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Tue, 21 Jul 2026 14:33:40 +0300
Subject: [PATCH] update dr_mp3 from mainstream (Jul.15, 2026.)
---
src/dr_mp3.h | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/dr_mp3.h b/src/dr_mp3.h
index 60a6c55e9..9243b4c2a 100644
--- a/src/dr_mp3.h
+++ b/src/dr_mp3.h
@@ -3202,11 +3202,25 @@ static drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drm
drmp3_bool32 isInfo = DRMP3_FALSE;
const drmp3_uint8* pTagData;
const drmp3_uint8* pTagDataBeg;
+ const void* pDataBufferEnd = NULL;
+ size_t frameBytes;
pTagDataBeg = pFirstFrameData + DRMP3_HDR_SIZE + (bs.pos/8);
pTagData = pTagDataBeg;
- if (firstFrameInfo.frame_bytes - (size_t)(pTagData - pFirstFrameData) < 8) {
+ /*
+ We need to determine how many bytes are actually available in pTagData. Unfortunately this is different depending on
+ whether or not it's being decoded from memory or callbacks.
+ */
+ if (pMP3->memory.pData != NULL && pMP3->memory.dataSize > 0) {
+ pDataBufferEnd = pMP3->memory.pData + pMP3->memory.dataSize;
+ } else {
+ pDataBufferEnd = pMP3->pData + pMP3->dataCapacity;
+ }
+
+ frameBytes = DRMP3_MIN((size_t)firstFrameInfo.frame_bytes, (size_t)((drmp3_uint8*)pDataBufferEnd - pTagDataBeg));
+
+ if (frameBytes - (size_t)(pTagData - pFirstFrameData) < 8) {
goto done_xing_info; /* Frame too small for a Xing/Info tag. */
}
@@ -3221,7 +3235,7 @@ static drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drm
pTagData += 8; /* Skip past the ID and flags. */
if (flags & 0x01) { /* FRAMES flag. */
- if (firstFrameInfo.frame_bytes - (size_t)(pTagData - pFirstFrameData) < 4) {
+ if (frameBytes - (size_t)(pTagData - pFirstFrameData) < 4) {
goto done_xing_info; /* Invalid Xing/Info tag. */
}
@@ -3230,7 +3244,7 @@ static drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drm
}
if (flags & 0x02) { /* BYTES flag. */
- if (firstFrameInfo.frame_bytes - (size_t)(pTagData - pFirstFrameData) < 4) {
+ if (frameBytes - (size_t)(pTagData - pFirstFrameData) < 4) {
goto done_xing_info; /* Invalid Xing/Info tag. */
}
@@ -3240,7 +3254,7 @@ static drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drm
}
if (flags & 0x04) { /* TOC flag. */
- if (firstFrameInfo.frame_bytes - (size_t)(pTagData - pFirstFrameData) < 100) {
+ if (frameBytes - (size_t)(pTagData - pFirstFrameData) < 100) {
goto done_xing_info; /* Invalid Xing/Info tag. */
}
@@ -3249,7 +3263,7 @@ static drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drm
}
if (flags & 0x08) { /* SCALE flag. */
- if (firstFrameInfo.frame_bytes - (size_t)(pTagData - pFirstFrameData) < 4) {
+ if (frameBytes - (size_t)(pTagData - pFirstFrameData) < 4) {
goto done_xing_info; /* Invalid Xing/Info tag. */
}
@@ -3261,7 +3275,7 @@ static drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drm
int delayInPCMFrames;
int paddingInPCMFrames;
- if (firstFrameInfo.frame_bytes - (size_t)(pTagData - pFirstFrameData) < 36) {
+ if (frameBytes - (size_t)(pTagData - pFirstFrameData) < 36) {
goto done_xing_info; /* Invalid Xing/Info tag. */
}