Commit e8c2ace2 authored by xidachen's avatar xidachen Committed by Commit bot

Supress integer-overflow in TexSubImage2D(3D)Impl

Currently in these two functions, we are not using CheckedNumeric. This
CL uses CheckedNumeric to ensure that integer-overflow will not happen

BUG=644271
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2310243002
Cr-Commit-Position: refs/heads/master@{#417137}
parent a2023abe
......@@ -19,6 +19,7 @@
#include <string>
#include "base/atomic_sequence_num.h"
#include "base/compiler_specific.h"
#include "base/numerics/safe_math.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
......@@ -2875,6 +2876,18 @@ void GLES2Implementation::TexSubImage2D(
pixels = reinterpret_cast<const int8_t*>(pixels) + skip_size;
ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_);
base::CheckedNumeric<GLint> checked_xoffset = xoffset;
checked_xoffset += width;
if (!checked_xoffset.IsValid()) {
SetGLError(GL_INVALID_VALUE, "TexSubImage2D", "xoffset + width overflows");
return;
}
base::CheckedNumeric<GLint> checked_yoffset = yoffset;
checked_yoffset += height;
if (!checked_yoffset.IsValid()) {
SetGLError(GL_INVALID_VALUE, "TexSubImage2D", "yoffset + height overflows");
return;
}
TexSubImage2DImpl(
target, level, xoffset, yoffset, width, height, format, type,
unpadded_row_size, pixels, padded_row_size, GL_FALSE, &buffer,
......@@ -3000,6 +3013,24 @@ void GLES2Implementation::TexSubImage3D(
pixels = reinterpret_cast<const int8_t*>(pixels) + skip_size;
ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_);
base::CheckedNumeric<GLint> checked_xoffset = xoffset;
checked_xoffset += width;
if (!checked_xoffset.IsValid()) {
SetGLError(GL_INVALID_VALUE, "TexSubImage3D", "xoffset + width overflows");
return;
}
base::CheckedNumeric<GLint> checked_yoffset = yoffset;
checked_yoffset += height;
if (!checked_yoffset.IsValid()) {
SetGLError(GL_INVALID_VALUE, "TexSubImage3D", "yoffset + height overflows");
return;
}
base::CheckedNumeric<GLint> checked_zoffset = zoffset;
checked_zoffset += depth;
if (!checked_zoffset.IsValid()) {
SetGLError(GL_INVALID_VALUE, "TexSubImage3D", "zoffset + depth overflows");
return;
}
TexSubImage3DImpl(
target, level, xoffset, yoffset, zoffset, width, height, depth,
format, type, unpadded_row_size, pixels, padded_row_size, GL_FALSE,
......
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