Skip to content

Commit 2ee4be6

Browse files
djgaperezdc
authored andcommitted
Cherry-pick 252432.896@safari-7614-branch (91df735). rdar://98583503
[WebGL] Harden texImageImpl byte length calculation rdar://98583503 Reviewed by Kimmo Kinnunen and Ryan Haddad. The calculation of the image size has been validated earlier but out of an abundance of caution, use checked arithmetic on size_t to perform calculation, returning a GL error on overflow. * Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp: (WebCore::WebGLRenderingContextBase::texImageImpl): Calculate imagePixelsByteLength with checked arithmetic to catch integer overflow. Canonical link: https://commits.webkit.org/252432.896@safari-7614-branch
1 parent ee69ee9 commit 2ee4be6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5350,12 +5350,18 @@ void WebGLRenderingContextBase::texImageImpl(TexImageFunctionID functionID, GCGL
53505350
GraphicsContextGL::DataFormat sourceDataFormat = imageExtractor.imageSourceFormat();
53515351
GraphicsContextGL::AlphaOp alphaOp = imageExtractor.imageAlphaOp();
53525352
const void* imagePixelData = imageExtractor.imagePixelData();
5353+
CheckedSize imagePixelByteLength(imageExtractor.imageWidth());
5354+
imagePixelByteLength *= imageExtractor.imageHeight();
5355+
imagePixelByteLength *= 4u;
5356+
GCGLsizei byteLength = 0;
5357+
if (imagePixelByteLength.hasOverflowed() || !convertSafely(imagePixelByteLength, byteLength)) {
5358+
synthesizeGLError(GraphicsContextGL::INVALID_OPERATION, functionName, "image too large");
5359+
return;
5360+
}
53535361

53545362
bool needConversion = true;
5355-
GCGLsizei byteLength = 0;
53565363
if (type == GraphicsContextGL::UNSIGNED_BYTE && sourceDataFormat == GraphicsContextGL::DataFormat::RGBA8 && format == GraphicsContextGL::RGBA && alphaOp == GraphicsContextGL::AlphaOp::DoNothing && !flipY && !selectingSubRectangle && depth == 1) {
53575364
needConversion = false;
5358-
byteLength = imageExtractor.imageWidth() * imageExtractor.imageHeight() * 4;
53595365
} else {
53605366
if (!m_context->packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtractor.imageHeight(), adjustedSourceImageRect, depth, imageExtractor.imageSourceUnpackAlignment(), unpackImageHeight, data)) {
53615367
synthesizeGLError(GraphicsContextGL::INVALID_VALUE, functionName, "packImage error");

0 commit comments

Comments
 (0)