Commit e99a9df2 by Alexis Hetu Committed by Commit Bot

Added integer overflow detection to ClipRectangle

Used angle::CheckedNumeric to make sure none of the additions in ClipRectangle produces an integer overflow. Bug: chromium:1091364 Change-Id: I23b7943259010bb6bfde3d8ebc41e87a04f5b4f6 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2404441Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Alexis Hétu <sugoi@chromium.org>
parent 1bd71b48
......@@ -558,13 +558,39 @@ bool Rectangle::encloses(const gl::Rectangle &inside) const
bool ClipRectangle(const Rectangle &source, const Rectangle &clip, Rectangle *intersection)
{
angle::CheckedNumeric<int> sourceX2(source.x);
sourceX2 += source.width;
if (!sourceX2.IsValid())
{
return false;
}
angle::CheckedNumeric<int> sourceY2(source.y);
sourceY2 += source.height;
if (!sourceY2.IsValid())
{
return false;
}
int minSourceX, maxSourceX, minSourceY, maxSourceY;
MinMax(source.x, source.x + source.width, &minSourceX, &maxSourceX);
MinMax(source.y, source.y + source.height, &minSourceY, &maxSourceY);
MinMax(source.x, sourceX2.ValueOrDie(), &minSourceX, &maxSourceX);
MinMax(source.y, sourceY2.ValueOrDie(), &minSourceY, &maxSourceY);
angle::CheckedNumeric<int> clipX2(clip.x);
clipX2 += clip.width;
if (!clipX2.IsValid())
{
return false;
}
angle::CheckedNumeric<int> clipY2(clip.y);
clipY2 += clip.height;
if (!clipY2.IsValid())
{
return false;
}
int minClipX, maxClipX, minClipY, maxClipY;
MinMax(clip.x, clip.x + clip.width, &minClipX, &maxClipX);
MinMax(clip.y, clip.y + clip.height, &minClipY, &maxClipY);
MinMax(clip.x, clipX2.ValueOrDie(), &minClipX, &maxClipX);
MinMax(clip.y, clipY2.ValueOrDie(), &minClipY, &maxClipY);
if (minSourceX >= maxClipX || maxSourceX <= minClipX || minSourceY >= maxClipY ||
maxSourceY <= minClipY)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment