| Summary: | Definite bug in SDL_FillRect | ||
|---|---|---|---|
| Product: | SDL | Reporter: | skaller <skaller> |
| Component: | video | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | critical | ||
| Priority: | P2 | CC: | dll, icculus, skaller |
| Version: | 2.0.3 | Keywords: | triage-2.0.4 |
| Hardware: | All | ||
| OS: | All | ||
| Attachments: |
Exhibits bug in SDL_FillRect.
fix for bug 2868 (SDL_FillRect bug) simplified test program for SDL_FillRect() crash fix for bug 2868 (SDL_FillRect bug) |
||
|
Description
skaller
2015-02-05 17:05:31 UTC
Created attachment 2041 [details]
Exhibits bug in SDL_FillRect.
Definite bug in SDL_FillRect.c exhibited by this attachment.
Here is the fix: AFTER Line 255 of SDL_FillRect.c add this line: if(SDL_RectEmpty(rect)) return 1; This prevents negative heights and widths or out of bounds starting pixel for fill crashing the subsequent calculations. Please also examine ALL similar code: blits, line drawing etc. Sorry, I cannot build SDL from source (OSX 10.6.8). This patch has been tested on Linux and prevents the test code from crashing. I would really like a fixed up SDL2.dmg for OSX since I cannot compile it myself. Created attachment 2042 [details] fix for bug 2868 (SDL_FillRect bug) Created attachment 2043 [details]
simplified test program for SDL_FillRect() crash
Hi Sam, Ryan, etc. I'm able to reproduce this bug on iOS + Win32. My guess, from looking at SDL's code, is that it occurs on other platforms as well. In summary, I think the bug can be condensed to the following: SDL_FillRect() can crash if the surface's clip-rect is completely out-of-bounds To reproduce: 1. set an SDL_Surface's clip-rect to something completely outside the bounds of the surface (via SDL_SetClipRect()). 2. call SDL_FillRect() on the surface, telling it to fill the entire rect (by passing in NULL as the 'rect/2nd-param). 3. crash! John's suggestion for a patch looks good. I've tested it, and encoded it into a patch. It takes the following statement from SDL_SetClipRect's documentation: 'If the clip rectangle doesn't intersect the surface, the function will return SDL_FALSE and blits will be completely clipped.' ... and applies it to SDL_FillRect(). I.e. if and when a surface's clip-rect is out-of-bounds, 'SDL_FillRect(surface, NULL, color)' does nothing. If you all like, I'd be happy to push this fix out to Mercurial. In addition to the patch, I've attached a simplified test case, which should reproduce on any platform. Cheers! -- David L. Created attachment 2044 [details] fix for bug 2868 (SDL_FillRect bug) Doh, I posted the simplified test program twice. Here's the patch! Looks good. David, go ahead and push this and resolve the bug. Thanks! --ryan. |