diff --git a/CHANGES.md b/CHANGES.md index 2386d7d8..17b20b1a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +v0.11.26 - TBD +===================== +* Fixed a crash when passing in null for the read or seek callbacks for a decoder. + + v0.11.25 - 2026-03-04 ===================== * Bug fixes to the WAV decoder. diff --git a/miniaudio.h b/miniaudio.h index 250e869c..3e94a18f 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -1,6 +1,6 @@ /* Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file. -miniaudio - v0.11.25 - 2026-03-04 +miniaudio - v0.11.26 - TBD David Reid - mackron@gmail.com @@ -3956,7 +3956,7 @@ extern "C" { #define MA_VERSION_MAJOR 0 #define MA_VERSION_MINOR 11 -#define MA_VERSION_REVISION 25 +#define MA_VERSION_REVISION 26 #define MA_VERSION_STRING MA_XSTRINGIFY(MA_VERSION_MAJOR) "." MA_XSTRINGIFY(MA_VERSION_MINOR) "." MA_XSTRINGIFY(MA_VERSION_REVISION) #if defined(_MSC_VER) && !defined(__clang__) @@ -10476,7 +10476,19 @@ typedef struct } ma_decoding_backend_vtable; -typedef ma_result (* ma_decoder_read_proc)(ma_decoder* pDecoder, void* pBufferOut, size_t bytesToRead, size_t* pBytesRead); /* Returns the number of bytes read. */ +/* +The read callback should return MA_SUCCESS if more than zero bytes were successfully read. If zero +bytes can be read because it reached the end of the file, return MA_AT_END. If any other error +occurs just return any other error code (it's fine to just generically return MA_ERROR). + +Return the actual number of bytes read in `pBytesRead`. Important note: if the number of bytes +actually read is less than the number of bytes requested (bytesToRead), miniaudio will treat it as +if the end of the file has been reached and it will stop decoding. This becomes relevant for things +like streaming data sources, such as internet streams. If you haven't yet received `bytesToRead` +from the network, you need to have your callback wait for it and then only return when the full +number of bytes can be output, or when you've reached the genuine end of the stream. +*/ +typedef ma_result (* ma_decoder_read_proc)(ma_decoder* pDecoder, void* pBufferOut, size_t bytesToRead, size_t* pBytesRead); typedef ma_result (* ma_decoder_seek_proc)(ma_decoder* pDecoder, ma_int64 byteOffset, ma_seek_origin origin); typedef ma_result (* ma_decoder_tell_proc)(ma_decoder* pDecoder, ma_int64* pCursor); @@ -75761,6 +75773,10 @@ static ma_result ma_decoder_on_seek(void* pUserData, ma_int64 offset, ma_seek_or ma_decoder* pDecoder = (ma_decoder*)pUserData; MA_ASSERT(pDecoder != NULL); + if (pDecoder->onSeek == NULL) { + return MA_NOT_IMPLEMENTED; + } + return pDecoder->onSeek(pDecoder, offset, origin); } @@ -75956,6 +75972,11 @@ static ma_result ma_decoder__preinit(ma_decoder_read_proc onRead, ma_decoder_see MA_ZERO_OBJECT(pDecoder); + /* A read callback must be available. */ + if (onRead == NULL) { + return MA_INVALID_ARGS; + } + dataSourceConfig = ma_data_source_config_init(); dataSourceConfig.pVTable = &ma_gDataSourceVTable_Decoder;