mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-04 08:56:25 +00:00
Added SDL_HINT_WAVE_CHUNK_LIMIT
This commit is contained in:
@@ -3340,6 +3340,17 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define SDL_HINT_WAVE_FACT_CHUNK "SDL_WAVE_FACT_CHUNK"
|
#define SDL_HINT_WAVE_FACT_CHUNK "SDL_WAVE_FACT_CHUNK"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A variable controlling the maximum number of chunks in a WAVE file.
|
||||||
|
*
|
||||||
|
* This sets an upper bound on the number of chunks in a WAVE file to avoid wasting time on malformed or corrupt WAVE files. This defaults to "10000".
|
||||||
|
*
|
||||||
|
* This hint should be set before calling SDL_LoadWAV() or SDL_LoadWAV_IO()
|
||||||
|
*
|
||||||
|
* \since This hint is available since SDL 3.0.0.
|
||||||
|
*/
|
||||||
|
#define SDL_HINT_WAVE_CHUNK_LIMIT "SDL_WAVE_CHUNK_LIMIT"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A variable controlling how the size of the RIFF chunk affects the loading
|
* A variable controlling how the size of the RIFF chunk affects the loading
|
||||||
* of a WAVE file.
|
* of a WAVE file.
|
||||||
@@ -3351,7 +3362,7 @@ extern "C" {
|
|||||||
* Note that files that have trailing data unrelated to the WAVE file or
|
* Note that files that have trailing data unrelated to the WAVE file or
|
||||||
* corrupt files may slow down the loading process without a reliable
|
* corrupt files may slow down the loading process without a reliable
|
||||||
* boundary. By default, SDL stops after 10000 chunks to prevent wasting time.
|
* boundary. By default, SDL stops after 10000 chunks to prevent wasting time.
|
||||||
* Use the environment variable SDL_WAVE_CHUNK_LIMIT to adjust this value.
|
* Use SDL_HINT_WAVE_CHUNK_LIMIT to adjust this value.
|
||||||
*
|
*
|
||||||
* The variable can be set to the following values:
|
* The variable can be set to the following values:
|
||||||
*
|
*
|
||||||
|
@@ -1774,7 +1774,7 @@ static int WaveLoad(SDL_IOStream *src, WaveFile *file, SDL_AudioSpec *spec, Uint
|
|||||||
int result;
|
int result;
|
||||||
Uint32 chunkcount = 0;
|
Uint32 chunkcount = 0;
|
||||||
Uint32 chunkcountlimit = 10000;
|
Uint32 chunkcountlimit = 10000;
|
||||||
const char *envchunkcountlimit;
|
const char *hint;
|
||||||
Sint64 RIFFstart, RIFFend, lastchunkpos;
|
Sint64 RIFFstart, RIFFend, lastchunkpos;
|
||||||
SDL_bool RIFFlengthknown = SDL_FALSE;
|
SDL_bool RIFFlengthknown = SDL_FALSE;
|
||||||
WaveFormat *format = &file->format;
|
WaveFormat *format = &file->format;
|
||||||
@@ -1787,10 +1787,10 @@ static int WaveLoad(SDL_IOStream *src, WaveFile *file, SDL_AudioSpec *spec, Uint
|
|||||||
SDL_zero(fmtchunk);
|
SDL_zero(fmtchunk);
|
||||||
SDL_zero(datachunk);
|
SDL_zero(datachunk);
|
||||||
|
|
||||||
envchunkcountlimit = SDL_getenv("SDL_WAVE_CHUNK_LIMIT");
|
hint = SDL_GetHint(SDL_HINT_WAVE_CHUNK_LIMIT);
|
||||||
if (envchunkcountlimit) {
|
if (hint) {
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
if (SDL_sscanf(envchunkcountlimit, "%u", &count) == 1) {
|
if (SDL_sscanf(hint, "%u", &count) == 1) {
|
||||||
chunkcountlimit = count <= SDL_MAX_UINT32 ? count : SDL_MAX_UINT32;
|
chunkcountlimit = count <= SDL_MAX_UINT32 ? count : SDL_MAX_UINT32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user