b=380494, allow zero-width/height surfaces (crash moz_cairo_win32_surface_get_image etc.), r+sr=roc

This commit is contained in:
vladimir@pobox.com 2007-05-15 13:27:10 -07:00
parent 66dd634a48
commit 46ddf124bb

View File

@ -273,18 +273,24 @@ gfxASurface::CairoStatus()
PRBool
gfxASurface::CheckSurfaceSize(const gfxIntSize& sz, PRInt32 limit)
{
if (sz.width <= 0 || sz.height <= 0)
if (sz.width < 0 || sz.height < 0) {
NS_ERROR("Surface width or height < 0!");
return PR_FALSE;
}
// check to make sure we don't overflow a 32-bit
PRInt32 tmp = sz.width * sz.height;
if (tmp / sz.height != sz.width)
if (tmp && tmp / sz.height != sz.width) {
NS_ERROR("Surface size too large (would overflow)!");
return PR_FALSE;
}
// always assume 4-byte stride
tmp = tmp * 4;
if (tmp / 4 != sz.width * sz.height)
if (tmp && tmp / 4 != sz.width * sz.height) {
NS_ERROR("Surface size too large (would overflow)!");
return PR_FALSE;
}
// reject images with sides bigger than limit
if (limit &&