mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-30 18:04:09 +03:00
Fix UB from out-of-range <stretch>
If there was a scaling mode value (serialized in the XML as <stretch> for legacy reasons) that was not 0 or 1 or 2, then the rectangle with the stretch information would not be initialized by get_stretch_info, which would lead to a crash, either from dividing by zero (most likely) or from reading an uninitialized value. To fix this, when reading <stretch>, normalize it to a sane default if the value is otherwise bogus. And for good measure, an assertion is added in get_stretch_info() if the value is still somehow bogus. Fixes #1155.
This commit is contained in:
@@ -3517,6 +3517,13 @@ void Graphics::get_stretch_info(SDL_Rect* rect)
|
||||
rect->w = width;
|
||||
rect->h = height;
|
||||
break;
|
||||
default:
|
||||
SDL_assert(0 && "Invalid scaling mode!");
|
||||
/* Width and height should be nonzero to avoid division by zero. */
|
||||
rect->x = 0;
|
||||
rect->y = 0;
|
||||
rect->w = width;
|
||||
rect->h = height;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user