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:
Sam Lantinga
2024-07-21 12:39:45 -07:00
parent 22bfbdbc02
commit bd27b89903
3 changed files with 43 additions and 0 deletions

View File

@@ -91,6 +91,7 @@ SDL_bool SDL_GetSpanEnclosingRect(int width, int height,
#define BIGSCALARTYPE Sint64
#define COMPUTEOUTCODE ComputeOutCode
#define ENCLOSEPOINTS_EPSILON 1
#define SDL_RECT_CAN_OVERFLOW SDL_RectCanOverflow
#define SDL_HASINTERSECTION SDL_HasRectIntersection
#define SDL_INTERSECTRECT SDL_GetRectIntersection
#define SDL_RECTEMPTY SDL_RectEmpty
@@ -105,6 +106,7 @@ SDL_bool SDL_GetSpanEnclosingRect(int width, int height,
#define BIGSCALARTYPE double
#define COMPUTEOUTCODE ComputeOutCodeFloat
#define ENCLOSEPOINTS_EPSILON 0.0f
#define SDL_RECT_CAN_OVERFLOW SDL_RectCanOverflowFloat
#define SDL_HASINTERSECTION SDL_HasRectIntersectionFloat
#define SDL_INTERSECTRECT SDL_GetRectIntersectionFloat
#define SDL_RECTEMPTY SDL_RectEmptyFloat