mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-21 06:45:44 +00:00
Prevent potential overflow in rectangle functions
We're limiting the functions to rects with positions and sizes < 1 billion for speed, which is totally fine for most SDL use cases. If you need rectangles larger than that, you can roll your own functions that use 64-bit intermediate values and do proper overflow handling of output values. Fixes https://github.com/libsdl-org/SDL/issues/8879
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* Original code: automated SDL rect test written by Edgar Simo "bobbens"
|
||||
* New/updated tests: aschiffler at ferzkopp dot net
|
||||
*/
|
||||
#include <limits.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_test.h>
|
||||
#include "testautomation_suites.h"
|
||||
@@ -161,6 +162,17 @@ static int rect_testIntersectRectAndLine(void *arg)
|
||||
intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
|
||||
validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 0, 0, 31);
|
||||
|
||||
/* Test some overflow cases */
|
||||
refRect.x = INT_MAX - 4;
|
||||
refRect.y = INT_MAX - 4;
|
||||
x1 = INT_MAX;
|
||||
y1 = INT_MIN;
|
||||
x2 = INT_MIN;
|
||||
y2 = INT_MAX;
|
||||
rect = refRect;
|
||||
intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
|
||||
validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, x1, y1, x2, y2);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user