diff options
| author | Ray <[email protected]> | 2024-04-20 23:58:22 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2024-04-20 23:58:22 +0200 |
| commit | cf47fbb20bbaacb986fcfe05f0c0e6c6d89c5690 (patch) | |
| tree | 11cc6f7cc2df77b8f2f6183c522794cb95660333 | |
| parent | 8f24d86c1f1ca282672ba467c17abf74415c4500 (diff) | |
| download | raylib-cf47fbb20bbaacb986fcfe05f0c0e6c6d89c5690.tar.gz raylib-cf47fbb20bbaacb986fcfe05f0c0e6c6d89c5690.zip | |
REVIEWED: `LoadImageRaw()` #3926
| -rw-r--r-- | src/rtextures.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/rtextures.c b/src/rtextures.c index 0899accd..90c0de21 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -316,15 +316,18 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int unsigned char *dataPtr = fileData; unsigned int size = GetPixelDataSize(width, height, format); - // Offset file data to expected raw image by header size - if ((headerSize > 0) && ((headerSize + size) <= dataSize)) dataPtr += headerSize; - - image.data = RL_MALLOC(size); // Allocate required memory in bytes - memcpy(image.data, dataPtr, size); // Copy required data to image - image.width = width; - image.height = height; - image.mipmaps = 1; - image.format = format; + if (size <= dataSize) // Security check + { + // Offset file data to expected raw image by header size + if ((headerSize > 0) && ((headerSize + size) <= dataSize)) dataPtr += headerSize; + + image.data = RL_MALLOC(size); // Allocate required memory in bytes + memcpy(image.data, dataPtr, size); // Copy required data to image + image.width = width; + image.height = height; + image.mipmaps = 1; + image.format = format; + } UnloadFileData(fileData); } |
