asyncio: SDL_LoadFileAsync was not null-terminating the file data.

This commit is contained in:
Ryan C. Gordon 2025-03-20 15:43:45 -04:00
parent 85435d5a14
commit 10072bb07d
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 3 additions and 2 deletions

View File

@ -309,12 +309,13 @@ bool SDL_LoadFileAsync(const char *file, SDL_AsyncIOQueue *queue, void *userdata
if (asyncio) {
asyncio->oneshot = true;
void *ptr = NULL;
Uint8 *ptr = NULL;
const Sint64 flen = SDL_GetAsyncIOSize(asyncio);
if (flen >= 0) {
// !!! FIXME: check if flen > address space, since it'll truncate and we'll just end up with an incomplete buffer or a crash.
ptr = SDL_malloc((size_t) (flen + 1)); // over-allocate by one so we can add a null-terminator.
ptr = (Uint8 *) SDL_malloc((size_t) (flen + 1)); // over-allocate by one so we can add a null-terminator.
if (ptr) {
ptr[flen] = '\0';
retval = SDL_ReadAsyncIO(asyncio, ptr, 0, (Uint64) flen, queue, userdata);
if (!retval) {
SDL_free(ptr);