| 1 |
From 1df46ae9a0eed5aa9f58b179d2cc4af5d23f8bde Mon Sep 17 00:00:00 2001 |
| 2 |
From: David Reid <[email protected]> |
| 3 |
Date: Sun, 26 Apr 2026 07:08:13 +1000 |
| 4 |
Subject: [PATCH] Update dr_libs. |
| 5 |
|
| 6 |
--- |
| 7 |
miniaudio.h | 145 +++++++++++++++++++++++++++++++++++++++------------- |
| 8 |
1 file changed, 109 insertions(+), 36 deletions(-) |
| 9 |
|
| 10 |
diff --git a/miniaudio.h b/miniaudio.h |
| 11 |
index 5ede858e..a58ac69f 100644 |
| 12 |
--- a/miniaudio.h |
| 13 |
+++ b/miniaudio.h |
| 14 |
@@ -61956,7 +61956,7 @@ extern "C" { |
| 15 |
#define MA_DR_WAV_XSTRINGIFY(x) MA_DR_WAV_STRINGIFY(x) |
| 16 |
#define MA_DR_WAV_VERSION_MAJOR 0 |
| 17 |
#define MA_DR_WAV_VERSION_MINOR 14 |
| 18 |
-#define MA_DR_WAV_VERSION_REVISION 5 |
| 19 |
+#define MA_DR_WAV_VERSION_REVISION 6 |
| 20 |
#define MA_DR_WAV_VERSION_STRING MA_DR_WAV_XSTRINGIFY(MA_DR_WAV_VERSION_MAJOR) "." MA_DR_WAV_XSTRINGIFY(MA_DR_WAV_VERSION_MINOR) "." MA_DR_WAV_XSTRINGIFY(MA_DR_WAV_VERSION_REVISION) |
| 21 |
#include <stddef.h> |
| 22 |
#define MA_DR_WAVE_FORMAT_PCM 0x1 |
| 23 |
@@ -62391,7 +62391,7 @@ extern "C" { |
| 24 |
#define MA_DR_FLAC_XSTRINGIFY(x) MA_DR_FLAC_STRINGIFY(x) |
| 25 |
#define MA_DR_FLAC_VERSION_MAJOR 0 |
| 26 |
#define MA_DR_FLAC_VERSION_MINOR 13 |
| 27 |
-#define MA_DR_FLAC_VERSION_REVISION 3 |
| 28 |
+#define MA_DR_FLAC_VERSION_REVISION 4 |
| 29 |
#define MA_DR_FLAC_VERSION_STRING MA_DR_FLAC_XSTRINGIFY(MA_DR_FLAC_VERSION_MAJOR) "." MA_DR_FLAC_XSTRINGIFY(MA_DR_FLAC_VERSION_MINOR) "." MA_DR_FLAC_XSTRINGIFY(MA_DR_FLAC_VERSION_REVISION) |
| 30 |
#include <stddef.h> |
| 31 |
#if defined(_MSC_VER) && _MSC_VER >= 1700 |
| 32 |
@@ -62691,7 +62691,7 @@ extern "C" { |
| 33 |
#define MA_DR_MP3_XSTRINGIFY(x) MA_DR_MP3_STRINGIFY(x) |
| 34 |
#define MA_DR_MP3_VERSION_MAJOR 0 |
| 35 |
#define MA_DR_MP3_VERSION_MINOR 7 |
| 36 |
-#define MA_DR_MP3_VERSION_REVISION 3 |
| 37 |
+#define MA_DR_MP3_VERSION_REVISION 4 |
| 38 |
#define MA_DR_MP3_VERSION_STRING MA_DR_MP3_XSTRINGIFY(MA_DR_MP3_VERSION_MAJOR) "." MA_DR_MP3_XSTRINGIFY(MA_DR_MP3_VERSION_MINOR) "." MA_DR_MP3_XSTRINGIFY(MA_DR_MP3_VERSION_REVISION) |
| 39 |
#include <stddef.h> |
| 40 |
#define MA_DR_MP3_MAX_PCM_FRAMES_PER_MP3_FRAME 1152 |
| 41 |
@@ -80377,7 +80377,12 @@ MA_PRIVATE ma_result ma_dr_wav__read_chunk_header(ma_dr_wav_read_proc onRead, vo |
| 42 |
if (onRead(pUserData, sizeInBytes, 8) != 8) { |
| 43 |
return MA_INVALID_FILE; |
| 44 |
} |
| 45 |
- pHeaderOut->sizeInBytes = ma_dr_wav_bytes_to_u64(sizeInBytes) - 24; |
| 46 |
+ pHeaderOut->sizeInBytes = ma_dr_wav_bytes_to_u64(sizeInBytes); |
| 47 |
+ if (pHeaderOut->sizeInBytes >= 24) { |
| 48 |
+ pHeaderOut->sizeInBytes -= 24; |
| 49 |
+ } else { |
| 50 |
+ return MA_INVALID_FILE; |
| 51 |
+ } |
| 52 |
pHeaderOut->paddingSize = ma_dr_wav__chunk_padding_size_w64(pHeaderOut->sizeInBytes); |
| 53 |
*pRunningBytesReadOut += 24; |
| 54 |
} else { |
| 55 |
@@ -80545,7 +80550,7 @@ MA_PRIVATE ma_uint64 ma_dr_wav__read_smpl_to_metadata_obj(ma_dr_wav__metadata_pa |
| 56 |
ma_uint32 loopCount; |
| 57 |
ma_uint32 calculatedLoopCount; |
| 58 |
loopCount = ma_dr_wav_bytes_to_u32(smplHeaderData + 28); |
| 59 |
- calculatedLoopCount = (pChunkHeader->sizeInBytes - MA_DR_WAV_SMPL_BYTES) / MA_DR_WAV_SMPL_LOOP_BYTES; |
| 60 |
+ calculatedLoopCount = (ma_uint32)((pChunkHeader->sizeInBytes - MA_DR_WAV_SMPL_BYTES) / MA_DR_WAV_SMPL_LOOP_BYTES); |
| 61 |
if (loopCount != calculatedLoopCount) { |
| 62 |
return totalBytesRead; |
| 63 |
} |
| 64 |
@@ -80820,8 +80825,9 @@ MA_PRIVATE ma_uint64 ma_dr_wav__read_bext_to_metadata_obj(ma_dr_wav__metadata_pa |
| 65 |
if (extraBytes > 0) { |
| 66 |
pMetadata->data.bext.pCodingHistory = (char*)ma_dr_wav__metadata_get_memory(pParser, extraBytes + 1, 1); |
| 67 |
MA_DR_WAV_ASSERT(pMetadata->data.bext.pCodingHistory != NULL); |
| 68 |
- bytesRead += ma_dr_wav__metadata_parser_read(pParser, pMetadata->data.bext.pCodingHistory, extraBytes, NULL); |
| 69 |
- pMetadata->data.bext.codingHistorySize = (ma_uint32)ma_dr_wav__strlen(pMetadata->data.bext.pCodingHistory); |
| 70 |
+ pMetadata->data.bext.codingHistorySize = ma_dr_wav__metadata_parser_read(pParser, pMetadata->data.bext.pCodingHistory, extraBytes, NULL); |
| 71 |
+ pMetadata->data.bext.pCodingHistory[pMetadata->data.bext.codingHistorySize] = '\0'; |
| 72 |
+ bytesRead += pMetadata->data.bext.codingHistorySize; |
| 73 |
} else { |
| 74 |
pMetadata->data.bext.pCodingHistory = NULL; |
| 75 |
pMetadata->data.bext.codingHistorySize = 0; |
| 76 |
@@ -80963,8 +80969,8 @@ MA_PRIVATE ma_uint64 ma_dr_wav__metadata_process_chunk(ma_dr_wav__metadata_parse |
| 77 |
bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, buffer, sizeof(buffer), &bytesRead); |
| 78 |
if (bytesJustRead == sizeof(buffer)) { |
| 79 |
ma_uint32 loopCount = ma_dr_wav_bytes_to_u32(buffer); |
| 80 |
- ma_uint64 calculatedLoopCount; |
| 81 |
- calculatedLoopCount = (pChunkHeader->sizeInBytes - MA_DR_WAV_SMPL_BYTES) / MA_DR_WAV_SMPL_LOOP_BYTES; |
| 82 |
+ ma_uint32 calculatedLoopCount; |
| 83 |
+ calculatedLoopCount = (ma_uint32)((pChunkHeader->sizeInBytes - MA_DR_WAV_SMPL_BYTES) / MA_DR_WAV_SMPL_LOOP_BYTES); |
| 84 |
if (calculatedLoopCount == loopCount) { |
| 85 |
bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, buffer, sizeof(buffer), &bytesRead); |
| 86 |
if (bytesJustRead == sizeof(buffer)) { |
| 87 |
@@ -81378,6 +81384,9 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p |
| 88 |
if (((pWav->container == ma_dr_wav_container_riff || pWav->container == ma_dr_wav_container_rifx || pWav->container == ma_dr_wav_container_rf64) && ma_dr_wav_fourcc_equal(header.id.fourcc, "fmt ")) || |
| 89 |
((pWav->container == ma_dr_wav_container_w64) && ma_dr_wav_guid_equal(header.id.guid, ma_dr_wavGUID_W64_FMT))) { |
| 90 |
ma_uint8 fmtData[16]; |
| 91 |
+ if (header.sizeInBytes < sizeof(fmtData)) { |
| 92 |
+ return MA_FALSE; |
| 93 |
+ } |
| 94 |
foundChunk_fmt = MA_TRUE; |
| 95 |
if (pWav->onRead(pWav->pUserData, fmtData, sizeof(fmtData)) != sizeof(fmtData)) { |
| 96 |
return MA_FALSE; |
| 97 |
@@ -81715,6 +81724,10 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p |
| 98 |
blockCount += 1; |
| 99 |
} |
| 100 |
totalBlockHeaderSizeInBytes = blockCount * (6*fmt.channels); |
| 101 |
+ if (totalBlockHeaderSizeInBytes >= dataChunkSize) { |
| 102 |
+ ma_dr_wav_free(pWav->pMetadata, &pWav->allocationCallbacks); |
| 103 |
+ return MA_FALSE; |
| 104 |
+ } |
| 105 |
pWav->totalPCMFrameCount = ((dataChunkSize - totalBlockHeaderSizeInBytes) * 2) / fmt.channels; |
| 106 |
} |
| 107 |
if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_DVI_ADPCM) { |
| 108 |
@@ -81724,6 +81737,10 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p |
| 109 |
blockCount += 1; |
| 110 |
} |
| 111 |
totalBlockHeaderSizeInBytes = blockCount * (4*fmt.channels); |
| 112 |
+ if (totalBlockHeaderSizeInBytes >= dataChunkSize) { |
| 113 |
+ ma_dr_wav_free(pWav->pMetadata, &pWav->allocationCallbacks); |
| 114 |
+ return MA_FALSE; |
| 115 |
+ } |
| 116 |
pWav->totalPCMFrameCount = ((dataChunkSize - totalBlockHeaderSizeInBytes) * 2) / fmt.channels; |
| 117 |
pWav->totalPCMFrameCount += blockCount; |
| 118 |
} |
| 119 |
@@ -83438,6 +83455,9 @@ MA_PRIVATE void ma_dr_wav__pcm_to_s16(ma_int16* pOut, const ma_uint8* pIn, size_ |
| 120 |
sample |= (ma_uint64)(pIn[j]) << shift; |
| 121 |
shift += 8; |
| 122 |
} |
| 123 |
+ if (!ma_dr_wav__is_little_endian()) { |
| 124 |
+ sample = ma_dr_wav__bswap64(sample); |
| 125 |
+ } |
| 126 |
pIn += j; |
| 127 |
*pOut++ = (ma_int16)((ma_int64)sample >> 48); |
| 128 |
} |
| 129 |
@@ -83779,6 +83799,9 @@ MA_PRIVATE void ma_dr_wav__pcm_to_f32(float* pOut, const ma_uint8* pIn, size_t s |
| 130 |
sample |= (ma_uint64)(pIn[j]) << shift; |
| 131 |
shift += 8; |
| 132 |
} |
| 133 |
+ if (!ma_dr_wav__is_little_endian()) { |
| 134 |
+ sample = ma_dr_wav__bswap64(sample); |
| 135 |
+ } |
| 136 |
pIn += j; |
| 137 |
*pOut++ = (float)((ma_int64)sample / 9223372036854775807.0); |
| 138 |
} |
| 139 |
@@ -84143,6 +84166,9 @@ MA_PRIVATE void ma_dr_wav__pcm_to_s32(ma_int32* pOut, const ma_uint8* pIn, size_ |
| 140 |
sample |= (ma_uint64)(pIn[j]) << shift; |
| 141 |
shift += 8; |
| 142 |
} |
| 143 |
+ if (!ma_dr_wav__is_little_endian()) { |
| 144 |
+ sample = ma_dr_wav__bswap64(sample); |
| 145 |
+ } |
| 146 |
pIn += j; |
| 147 |
*pOut++ = (ma_int32)((ma_int64)sample >> 32); |
| 148 |
} |
| 149 |
@@ -85077,6 +85103,7 @@ static MA_INLINE ma_bool32 ma_dr_flac_has_sse41(void) |
| 150 |
#ifndef MA_DR_FLAC_ZERO_OBJECT |
| 151 |
#define MA_DR_FLAC_ZERO_OBJECT(p) MA_DR_FLAC_ZERO_MEMORY((p), sizeof(*(p))) |
| 152 |
#endif |
| 153 |
+#define MA_DR_FLAC_MIN(a, b) (((a) < (b)) ? (a) : (b)) |
| 154 |
#define MA_DR_FLAC_MAX_SIMD_VECTOR_SIZE 64 |
| 155 |
#define MA_DR_FLAC_SUBFRAME_CONSTANT 0 |
| 156 |
#define MA_DR_FLAC_SUBFRAME_VERBATIM 1 |
| 157 |
@@ -88358,7 +88385,6 @@ static ma_bool32 ma_dr_flac__seek_to_pcm_frame__binary_search_internal(ma_dr_fla |
| 158 |
break; |
| 159 |
} |
| 160 |
} else { |
| 161 |
- const float approxCompressionRatio = (ma_int64)(lastSuccessfulSeekOffset - pFlac->firstFLACFramePosInBytes) / ((ma_int64)(pcmRangeLo * pFlac->channels * pFlac->bitsPerSample)/8.0f); |
| 162 |
if (pcmRangeLo > pcmFrameIndex) { |
| 163 |
byteRangeHi = lastSuccessfulSeekOffset; |
| 164 |
if (byteRangeLo > byteRangeHi) { |
| 165 |
@@ -88376,11 +88402,12 @@ static ma_bool32 ma_dr_flac__seek_to_pcm_frame__binary_search_internal(ma_dr_fla |
| 166 |
break; |
| 167 |
} |
| 168 |
} else { |
| 169 |
+ const double approxCompressionRatio = (ma_int64)(lastSuccessfulSeekOffset - pFlac->firstFLACFramePosInBytes) / ((ma_int64)(pcmRangeLo * pFlac->channels * pFlac->bitsPerSample)/8.0); |
| 170 |
byteRangeLo = lastSuccessfulSeekOffset; |
| 171 |
if (byteRangeHi < byteRangeLo) { |
| 172 |
byteRangeHi = byteRangeLo; |
| 173 |
} |
| 174 |
- targetByte = lastSuccessfulSeekOffset + (ma_uint64)(((ma_int64)((pcmFrameIndex-pcmRangeLo) * pFlac->channels * pFlac->bitsPerSample)/8.0f) * approxCompressionRatio); |
| 175 |
+ targetByte = lastSuccessfulSeekOffset + (ma_uint64)(((ma_int64)((pcmFrameIndex-pcmRangeLo) * pFlac->channels * pFlac->bitsPerSample)/8.0) * approxCompressionRatio); |
| 176 |
if (targetByte > byteRangeHi) { |
| 177 |
targetByte = byteRangeHi; |
| 178 |
} |
| 179 |
@@ -88661,7 +88688,7 @@ static void* ma_dr_flac__realloc_from_callbacks(void* p, size_t szNew, size_t sz |
| 180 |
return NULL; |
| 181 |
} |
| 182 |
if (p != NULL) { |
| 183 |
- MA_DR_FLAC_COPY_MEMORY(p2, p, szOld); |
| 184 |
+ MA_DR_FLAC_COPY_MEMORY(p2, p, MA_DR_FLAC_MIN(szNew, szOld)); |
| 185 |
pAllocationCallbacks->onFree(p, pAllocationCallbacks->pUserData); |
| 186 |
} |
| 187 |
return p2; |
| 188 |
@@ -88679,10 +88706,19 @@ static void ma_dr_flac__free_from_callbacks(void* p, const ma_allocation_callbac |
| 189 |
} |
| 190 |
static ma_bool32 ma_dr_flac__read_and_decode_metadata(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, ma_dr_flac_tell_proc onTell, ma_dr_flac_meta_proc onMeta, void* pUserData, void* pUserDataMD, ma_uint64* pFirstFramePos, ma_uint64* pSeektablePos, ma_uint32* pSeekpointCount, ma_allocation_callbacks* pAllocationCallbacks) |
| 191 |
{ |
| 192 |
- ma_uint64 runningFilePos = 42; |
| 193 |
- ma_uint64 seektablePos = 0; |
| 194 |
- ma_uint32 seektableSize = 0; |
| 195 |
- (void)onTell; |
| 196 |
+ ma_uint64 runningFilePos = 42; |
| 197 |
+ ma_uint64 seektablePos = 0; |
| 198 |
+ ma_uint32 seektableSize = 0; |
| 199 |
+ ma_int64 fileSize = 0; |
| 200 |
+ ma_bool32 hasKnownFileSize = MA_FALSE; |
| 201 |
+ if (onTell != NULL && onSeek != NULL) { |
| 202 |
+ if (onSeek(pUserData, 0, MA_DR_FLAC_SEEK_END)) { |
| 203 |
+ if (onTell(pUserData, &fileSize)) { |
| 204 |
+ hasKnownFileSize = MA_TRUE; |
| 205 |
+ } |
| 206 |
+ onSeek(pUserData, runningFilePos, MA_DR_FLAC_SEEK_SET); |
| 207 |
+ } |
| 208 |
+ } |
| 209 |
for (;;) { |
| 210 |
ma_dr_flac_metadata metadata; |
| 211 |
ma_uint8 isLastBlock = 0; |
| 212 |
@@ -88691,6 +88727,9 @@ static ma_bool32 ma_dr_flac__read_and_decode_metadata(ma_dr_flac_read_proc onRea |
| 213 |
if (ma_dr_flac__read_and_decode_block_header(onRead, pUserData, &isLastBlock, &blockType, &blockSize) == MA_FALSE) { |
| 214 |
return MA_FALSE; |
| 215 |
} |
| 216 |
+ if (hasKnownFileSize && (blockSize > ((ma_uint64)fileSize - runningFilePos))) { |
| 217 |
+ return MA_FALSE; |
| 218 |
+ } |
| 219 |
runningFilePos += 4; |
| 220 |
metadata.type = blockType; |
| 221 |
metadata.rawDataSize = 0; |
| 222 |
@@ -88779,7 +88818,7 @@ static ma_bool32 ma_dr_flac__read_and_decode_metadata(ma_dr_flac_read_proc onRea |
| 223 |
ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks); |
| 224 |
return MA_FALSE; |
| 225 |
} |
| 226 |
- metadata.data.vorbis_comment.vendor = pRunningData; pRunningData += metadata.data.vorbis_comment.vendorLength; |
| 227 |
+ metadata.data.vorbis_comment.vendor = pRunningData; pRunningData += metadata.data.vorbis_comment.vendorLength; |
| 228 |
metadata.data.vorbis_comment.commentCount = ma_dr_flac__le2host_32_ptr_unaligned(pRunningData); pRunningData += 4; |
| 229 |
if ((pRunningDataEnd - pRunningData) / sizeof(ma_uint32) < metadata.data.vorbis_comment.commentCount) { |
| 230 |
ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks); |
| 231 |
@@ -88912,12 +88951,16 @@ static ma_bool32 ma_dr_flac__read_and_decode_metadata(ma_dr_flac_read_proc onRea |
| 232 |
} |
| 233 |
blockSizeRemaining -= 4; |
| 234 |
metadata.data.picture.mimeLength = ma_dr_flac__be2host_32(metadata.data.picture.mimeLength); |
| 235 |
+ if (blockSizeRemaining < metadata.data.picture.mimeLength) { |
| 236 |
+ result = MA_FALSE; |
| 237 |
+ goto done_flac; |
| 238 |
+ } |
| 239 |
pMime = (char*)ma_dr_flac__malloc_from_callbacks(metadata.data.picture.mimeLength + 1, pAllocationCallbacks); |
| 240 |
if (pMime == NULL) { |
| 241 |
result = MA_FALSE; |
| 242 |
goto done_flac; |
| 243 |
} |
| 244 |
- if (blockSizeRemaining < metadata.data.picture.mimeLength || onRead(pUserData, pMime, metadata.data.picture.mimeLength) != metadata.data.picture.mimeLength) { |
| 245 |
+ if (onRead(pUserData, pMime, metadata.data.picture.mimeLength) != metadata.data.picture.mimeLength) { |
| 246 |
result = MA_FALSE; |
| 247 |
goto done_flac; |
| 248 |
} |
| 249 |
@@ -88930,12 +88973,16 @@ static ma_bool32 ma_dr_flac__read_and_decode_metadata(ma_dr_flac_read_proc onRea |
| 250 |
} |
| 251 |
blockSizeRemaining -= 4; |
| 252 |
metadata.data.picture.descriptionLength = ma_dr_flac__be2host_32(metadata.data.picture.descriptionLength); |
| 253 |
+ if (blockSizeRemaining < metadata.data.picture.descriptionLength) { |
| 254 |
+ result = MA_FALSE; |
| 255 |
+ goto done_flac; |
| 256 |
+ } |
| 257 |
pDescription = (char*)ma_dr_flac__malloc_from_callbacks(metadata.data.picture.descriptionLength + 1, pAllocationCallbacks); |
| 258 |
if (pDescription == NULL) { |
| 259 |
result = MA_FALSE; |
| 260 |
goto done_flac; |
| 261 |
} |
| 262 |
- if (blockSizeRemaining < metadata.data.picture.descriptionLength || onRead(pUserData, pDescription, metadata.data.picture.descriptionLength) != metadata.data.picture.descriptionLength) { |
| 263 |
+ if (onRead(pUserData, pDescription, metadata.data.picture.descriptionLength) != metadata.data.picture.descriptionLength) { |
| 264 |
result = MA_FALSE; |
| 265 |
goto done_flac; |
| 266 |
} |
| 267 |
@@ -89894,9 +89941,15 @@ static ma_dr_flac* ma_dr_flac_open_with_metadata_private(ma_dr_flac_read_proc on |
| 268 |
#endif |
| 269 |
return NULL; |
| 270 |
} |
| 271 |
+ if ((0xFFFFFFFF - (seekpointCount * sizeof(ma_dr_flac_seekpoint))) < allocationSize) { |
| 272 |
+ #ifndef MA_DR_FLAC_NO_OGG |
| 273 |
+ ma_dr_flac__free_from_callbacks(pOggbs, &allocationCallbacks); |
| 274 |
+ #endif |
| 275 |
+ return NULL; |
| 276 |
+ } |
| 277 |
allocationSize += seekpointCount * sizeof(ma_dr_flac_seekpoint); |
| 278 |
} |
| 279 |
- pFlac = (ma_dr_flac*)ma_dr_flac__malloc_from_callbacks(allocationSize, &allocationCallbacks); |
| 280 |
+ pFlac = (ma_dr_flac*)ma_dr_flac__malloc_from_callbacks((size_t)allocationSize, &allocationCallbacks); |
| 281 |
if (pFlac == NULL) { |
| 282 |
#ifndef MA_DR_FLAC_NO_OGG |
| 283 |
ma_dr_flac__free_from_callbacks(pOggbs, &allocationCallbacks); |
| 284 |
@@ -92769,7 +92822,10 @@ MA_API const char* ma_dr_mp3_version_string(void) |
| 285 |
#define MA_DR_MP3_MIN(a, b) ((a) > (b) ? (b) : (a)) |
| 286 |
#define MA_DR_MP3_MAX(a, b) ((a) < (b) ? (b) : (a)) |
| 287 |
#if !defined(MA_DR_MP3_NO_SIMD) |
| 288 |
-#if !defined(MA_DR_MP3_ONLY_SIMD) && (defined(_M_X64) || defined(__x86_64__) || defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)) |
| 289 |
+#if !defined(MA_DR_MP3_ONLY_SIMD) && ((defined(_MSC_VER) && _MSC_VER >= 1400) && defined(_M_X64)) || ((defined(__i386) || defined(_M_IX86) || defined(__i386__) || defined(__x86_64__)) && ((defined(_M_IX86_FP) && _M_IX86_FP == 2) || defined(__SSE2__))) |
| 290 |
+#define MA_DR_MP3_ONLY_SIMD |
| 291 |
+#endif |
| 292 |
+#if !defined(MA_DR_MP3_ONLY_SIMD) && (defined(__ARM_NEON) || defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)) |
| 293 |
#define MA_DR_MP3_ONLY_SIMD |
| 294 |
#endif |
| 295 |
#if ((defined(_MSC_VER) && _MSC_VER >= 1400) && defined(_M_X64)) || ((defined(__i386) || defined(_M_IX86) || defined(__i386__) || defined(__x86_64__)) && ((defined(_M_IX86_FP) && _M_IX86_FP == 2) || defined(__SSE2__))) |
| 296 |
@@ -94926,6 +94982,9 @@ static ma_bool32 ma_dr_mp3_init_internal(ma_dr_mp3* pMP3, ma_dr_mp3_read_proc on |
| 297 |
const ma_uint8* pTagDataBeg; |
| 298 |
pTagDataBeg = pFirstFrameData + MA_DR_MP3_HDR_SIZE + (bs.pos/8); |
| 299 |
pTagData = pTagDataBeg; |
| 300 |
+ if (firstFrameInfo.frame_bytes - (size_t)(pTagData - pFirstFrameData) < 8) { |
| 301 |
+ goto done_xing_info; |
| 302 |
+ } |
| 303 |
isXing = (pTagData[0] == 'X' && pTagData[1] == 'i' && pTagData[2] == 'n' && pTagData[3] == 'g'); |
| 304 |
isInfo = (pTagData[0] == 'I' && pTagData[1] == 'n' && pTagData[2] == 'f' && pTagData[3] == 'o'); |
| 305 |
if (isXing || isInfo) { |
| 306 |
@@ -94933,33 +94992,46 @@ static ma_bool32 ma_dr_mp3_init_internal(ma_dr_mp3* pMP3, ma_dr_mp3_read_proc on |
| 307 |
ma_uint32 flags = pTagData[7]; |
| 308 |
pTagData += 8; |
| 309 |
if (flags & 0x01) { |
| 310 |
+ if (firstFrameInfo.frame_bytes - (size_t)(pTagData - pFirstFrameData) < 4) { |
| 311 |
+ goto done_xing_info; |
| 312 |
+ } |
| 313 |
detectedMP3FrameCount = (ma_uint32)pTagData[0] << 24 | (ma_uint32)pTagData[1] << 16 | (ma_uint32)pTagData[2] << 8 | (ma_uint32)pTagData[3]; |
| 314 |
pTagData += 4; |
| 315 |
} |
| 316 |
if (flags & 0x02) { |
| 317 |
+ if (firstFrameInfo.frame_bytes - (size_t)(pTagData - pFirstFrameData) < 4) { |
| 318 |
+ goto done_xing_info; |
| 319 |
+ } |
| 320 |
bytes = (ma_uint32)pTagData[0] << 24 | (ma_uint32)pTagData[1] << 16 | (ma_uint32)pTagData[2] << 8 | (ma_uint32)pTagData[3]; |
| 321 |
(void)bytes; |
| 322 |
pTagData += 4; |
| 323 |
} |
| 324 |
if (flags & 0x04) { |
| 325 |
+ if (firstFrameInfo.frame_bytes - (size_t)(pTagData - pFirstFrameData) < 100) { |
| 326 |
+ goto done_xing_info; |
| 327 |
+ } |
| 328 |
pTagData += 100; |
| 329 |
} |
| 330 |
if (flags & 0x08) { |
| 331 |
+ if (firstFrameInfo.frame_bytes - (size_t)(pTagData - pFirstFrameData) < 4) { |
| 332 |
+ goto done_xing_info; |
| 333 |
+ } |
| 334 |
pTagData += 4; |
| 335 |
} |
| 336 |
if (pTagData[0]) { |
| 337 |
+ int delayInPCMFrames; |
| 338 |
+ int paddingInPCMFrames; |
| 339 |
+ if (firstFrameInfo.frame_bytes - (size_t)(pTagData - pFirstFrameData) < 36) { |
| 340 |
+ goto done_xing_info; |
| 341 |
+ } |
| 342 |
pTagData += 21; |
| 343 |
- if (pTagData - pFirstFrameData + 14 < firstFrameInfo.frame_bytes) { |
| 344 |
- int delayInPCMFrames; |
| 345 |
- int paddingInPCMFrames; |
| 346 |
- delayInPCMFrames = (( (ma_uint32)pTagData[0] << 4) | ((ma_uint32)pTagData[1] >> 4)) + (528 + 1); |
| 347 |
- paddingInPCMFrames = ((((ma_uint32)pTagData[1] & 0xF) << 8) | ((ma_uint32)pTagData[2] )) - (528 + 1); |
| 348 |
- if (paddingInPCMFrames < 0) { |
| 349 |
- paddingInPCMFrames = 0; |
| 350 |
- } |
| 351 |
- pMP3->delayInPCMFrames = (ma_uint32)delayInPCMFrames; |
| 352 |
- pMP3->paddingInPCMFrames = (ma_uint32)paddingInPCMFrames; |
| 353 |
+ delayInPCMFrames = (( (ma_uint32)pTagData[0] << 4) | ((ma_uint32)pTagData[1] >> 4)) + (528 + 1); |
| 354 |
+ paddingInPCMFrames = ((((ma_uint32)pTagData[1] & 0xF) << 8) | ((ma_uint32)pTagData[2] )) - (528 + 1); |
| 355 |
+ if (paddingInPCMFrames < 0) { |
| 356 |
+ paddingInPCMFrames = 0; |
| 357 |
} |
| 358 |
+ pMP3->delayInPCMFrames = (ma_uint32)delayInPCMFrames; |
| 359 |
+ pMP3->paddingInPCMFrames = (ma_uint32)paddingInPCMFrames; |
| 360 |
} |
| 361 |
if (isXing) { |
| 362 |
pMP3->isVBR = MA_TRUE; |
| 363 |
@@ -94978,6 +95050,7 @@ static ma_bool32 ma_dr_mp3_init_internal(ma_dr_mp3* pMP3, ma_dr_mp3_read_proc on |
| 364 |
pMP3->streamCursor = pMP3->streamStartOffset; |
| 365 |
ma_dr_mp3dec_init(&pMP3->decoder); |
| 366 |
} |
| 367 |
+ done_xing_info:; |
| 368 |
} else { |
| 369 |
} |
| 370 |
} |
| 371 |
@@ -94987,7 +95060,7 @@ static ma_bool32 ma_dr_mp3_init_internal(ma_dr_mp3* pMP3, ma_dr_mp3_read_proc on |
| 372 |
return MA_FALSE; |
| 373 |
} |
| 374 |
if (detectedMP3FrameCount != 0xFFFFFFFF) { |
| 375 |
- pMP3->totalPCMFrameCount = detectedMP3FrameCount * firstFramePCMFrameCount; |
| 376 |
+ pMP3->totalPCMFrameCount = (ma_uint64)detectedMP3FrameCount * firstFramePCMFrameCount; |
| 377 |
} |
| 378 |
pMP3->channels = pMP3->mp3FrameChannels; |
| 379 |
pMP3->sampleRate = pMP3->mp3FrameSampleRate; |
| 380 |
@@ -95287,7 +95360,7 @@ MA_API ma_uint64 ma_dr_mp3_read_pcm_frames_f32(ma_dr_mp3* pMP3, ma_uint64 frames |
| 381 |
return ma_dr_mp3_read_pcm_frames_raw(pMP3, framesToRead, pBufferOut); |
| 382 |
#else |
| 383 |
{ |
| 384 |
- ma_int16 pTempS16[8192]; |
| 385 |
+ ma_int16 pTempS16[1152*2]; |
| 386 |
ma_uint64 totalPCMFramesRead = 0; |
| 387 |
while (totalPCMFramesRead < framesToRead) { |
| 388 |
ma_uint64 framesJustRead; |
| 389 |
@@ -95316,7 +95389,7 @@ MA_API ma_uint64 ma_dr_mp3_read_pcm_frames_s16(ma_dr_mp3* pMP3, ma_uint64 frames |
| 390 |
return ma_dr_mp3_read_pcm_frames_raw(pMP3, framesToRead, pBufferOut); |
| 391 |
#else |
| 392 |
{ |
| 393 |
- float pTempF32[4096]; |
| 394 |
+ float pTempF32[1152*2]; |
| 395 |
ma_uint64 totalPCMFramesRead = 0; |
| 396 |
while (totalPCMFramesRead < framesToRead) { |
| 397 |
ma_uint64 framesJustRead; |
| 398 |
@@ -95647,7 +95720,7 @@ static float* ma_dr_mp3__full_read_and_close_f32(ma_dr_mp3* pMP3, ma_dr_mp3_conf |
| 399 |
ma_uint64 totalFramesRead = 0; |
| 400 |
ma_uint64 framesCapacity = 0; |
| 401 |
float* pFrames = NULL; |
| 402 |
- float temp[4096]; |
| 403 |
+ float temp[1152*2]; |
| 404 |
MA_DR_MP3_ASSERT(pMP3 != NULL); |
| 405 |
for (;;) { |
| 406 |
ma_uint64 framesToReadRightNow = MA_DR_MP3_COUNTOF(temp) / pMP3->channels; |
| 407 |
@@ -95700,7 +95773,7 @@ static ma_int16* ma_dr_mp3__full_read_and_close_s16(ma_dr_mp3* pMP3, ma_dr_mp3_c |
| 408 |
ma_uint64 totalFramesRead = 0; |
| 409 |
ma_uint64 framesCapacity = 0; |
| 410 |
ma_int16* pFrames = NULL; |
| 411 |
- ma_int16 temp[4096]; |
| 412 |
+ ma_int16 temp[1152*2]; |
| 413 |
MA_DR_MP3_ASSERT(pMP3 != NULL); |
| 414 |
for (;;) { |
| 415 |
ma_uint64 framesToReadRightNow = MA_DR_MP3_COUNTOF(temp) / pMP3->channels; |
| 416 |
-- |
| 417 |
2.53.0 |
| 418 |
|