Commit 97fefd050976bbbfca9608499f6a7d9fb86e70db

Sam Lantinga 2019-07-30T11:00:00

Fixed bug 4538 - validate image size when loading BMP files

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c
index 0b68918..a06b0c9 100644
--- a/src/video/SDL_bmp.c
+++ b/src/video/SDL_bmp.c
@@ -226,6 +226,11 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
             SDL_RWseek(src, (biSize - headerSize), RW_SEEK_CUR);
         }
     }
+    if (biWidth <= 0 || biHeight == 0) {
+        SDL_SetError("BMP file with bad dimensions (%dx%d)", biWidth, biHeight);
+        was_error = SDL_TRUE;
+        goto done;
+    }
     if (biHeight < 0) {
         topDown = SDL_TRUE;
         biHeight = -biHeight;