Bug 1250710 - Offset reduces available bytes. - r=jrmuizel draft
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 16 Jun 2016 07:29:02 -0700
changeset 380203 96cbc580006098d6a77b5cf018baa1f6e7a521da
parent 380202 fddd5fbb74f5c3c474df38a2694959813d17c432
child 380204 9c0737d306b8f6b7df60be828f3f82cdd8ab330c
push id21161
push userbmo:jgilbert@mozilla.com
push dateTue, 21 Jun 2016 02:12:51 +0000
reviewersjrmuizel
bugs1250710
milestone50.0a1
Bug 1250710 - Offset reduces available bytes. - r=jrmuizel MozReview-Commit-ID: 6tHKEQQ0jN8
dom/canvas/WebGLContextGL.cpp
--- a/dom/canvas/WebGLContextGL.cpp
+++ b/dom/canvas/WebGLContextGL.cpp
@@ -1690,26 +1690,31 @@ WebGL2Context::ReadPixels(GLint x, GLint
         return;
     }
 
     if (offset < 0) {
         ErrorInvalidValue("readPixels: offset must not be negative.");
         return;
     }
 
-    const auto bytesAvailable = mBoundPixelPackBuffer->ByteLength();
+    const auto bufferLen = mBoundPixelPackBuffer->ByteLength();
+    const auto bytesAvailable = CheckedInt<intptr_t>(bufferLen) - offset;
+    if (!bytesAvailable.isValid() || bytesAvailable.value() < 0) {
+        ErrorInvalidOperation("readPixels: Offset too large for PBO.");
+        return;
+    }
 
     uint8_t bytesPerPixel;
     uint32_t startOffset;
     uint32_t rowStride;
     uint32_t readX, readY;
     uint32_t writeX, writeY;
     uint32_t rwWidth, rwHeight;
     const webgl::FormatInfo* srcFormat;
-    if (!ValidateReadPixels(x, y, width, height, format, type, bytesAvailable,
+    if (!ValidateReadPixels(x, y, width, height, format, type, bytesAvailable.value(),
                             &bytesPerPixel, &startOffset, &rowStride, &readX, &readY,
                             &writeX, &writeY, &rwWidth, &rwHeight, &srcFormat))
     {
         return;
     }
 
     {
         const auto bytesPerType = webgl::BytesPerPixel({LOCAL_GL_RED, type});