mirror of
https://github.com/Ryujinx/SDL.git
synced 2024-12-22 19:15:29 +00:00
testautomation_surface: Really make pitch + alignment overflow
Adding 3 bytes of alignment to 0x7fff'ffff is not enough to make it overflow a 4-byte unsigned size_t, so this test was not exercising the intended failure mode. We cannot actually make this overflow with a signed 32-bit width and an 8-bit format: the maximum width is not enough to achieve that. However, if we switch to a 24-bit format, we can make the calculation overflow. In SDL 2, this test bug was hidden by the fact that allocating 0x7fff'ffff bytes on a 32-bit platform will usually fail, and SDL 2 reported both "malloc() failed" and "this amount of memory is too large for a size_t" with the same error code. Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
cc7fe8c255
commit
62d063f735
|
@ -766,7 +766,9 @@ int surface_testOverflow(void *arg)
|
|||
|
||||
if (sizeof(size_t) == 4 && sizeof(int) >= 4) {
|
||||
expectedError = "Out of memory";
|
||||
surface = SDL_CreateRGBSurfaceWithFormat(0, SDL_MAX_SINT32, 1, 8, SDL_PIXELFORMAT_INDEX8);
|
||||
/* 0x5555'5555 * 3bpp = 0xffff'ffff which fits in size_t, but adding
|
||||
* alignment padding makes it overflow */
|
||||
surface = SDL_CreateRGBSurfaceWithFormat(0, 0x55555555, 1, 24, SDL_PIXELFORMAT_RGB24);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width + alignment");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
|
|
Loading…
Reference in a new issue