diff --git a/gfx/angle/src/libANGLE/formatutils.cpp b/gfx/angle/src/libANGLE/formatutils.cpp index 9a8c1b7900..caeaf6c6e1 100644 --- a/gfx/angle/src/libANGLE/formatutils.cpp +++ b/gfx/angle/src/libANGLE/formatutils.cpp @@ -863,13 +863,22 @@ gl::ErrorOrResult InternalFormat::computeDepthPitch(GLenum formatType, GLint rowLength, GLint imageHeight) const { - GLuint rows = - (imageHeight > 0 ? static_cast(imageHeight) : static_cast(height)); + CheckedNumeric pixelsHeight(imageHeight > 0 ? static_cast(imageHeight) + : static_cast(height)); + + CheckedNumeric rowCount; + if (compressed) { + CheckedNumeric checkedBlockHeight(compressedBlockHeight); + rowCount = (pixelsHeight + checkedBlockHeight - 1u) / checkedBlockHeight; + } else { + rowCount = pixelsHeight; + } + GLuint rowPitch = 0; ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch); CheckedNumeric checkedRowPitch(rowPitch); - auto depthPitch = checkedRowPitch * rows; + auto depthPitch = checkedRowPitch * rowCount; ANGLE_TRY_CHECKED_MATH(depthPitch); return depthPitch.ValueOrDie(); }