Commit dbcced8e by Geoff Lang Committed by Commit Bot

When validating image size, use format for SubImage calls.

internalFormat is GL_NONE when validating these calls for glTexSubImage and leads to an expected minimum size of 0. Add extra unsized formats that are never supported to the format tables. These are needed for determining the size of input data. BUG=angleproject:2054 Change-Id: Ic827a279a246ff92c9f279232574521692b1c6f2 Reviewed-on: https://chromium-review.googlesource.com/526356Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent f18b8606
...@@ -711,13 +711,17 @@ static InternalFormatInfoMap BuildInternalFormatInfoMap() ...@@ -711,13 +711,17 @@ static InternalFormatInfoMap BuildInternalFormatInfoMap()
// Unsized formats // Unsized formats
// | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable | // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, AlwaysSupported); AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, AlwaysSupported);
AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, AlwaysSupported); AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, AlwaysSupported);
AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, AlwaysSupported); AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, AlwaysSupported);
AddRGBAFormat(&map, GL_RGB, false, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported); AddRGBAFormat(&map, GL_RGB, false, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
AddRGBAFormat(&map, GL_RGBA, false, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported); AddRGBAFormat(&map, GL_RGBA, false, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
AddRGBAFormat(&map, GL_RGBA, false, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported); AddRGBAFormat(&map, GL_RGBA, false, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported); AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
AddRGBAFormat(&map, GL_RGBA, false, 10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported); AddRGBAFormat(&map, GL_RGBA, false, 10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
AddRGBAFormat(&map, GL_SRGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, NeverSupported, AlwaysSupported); AddRGBAFormat(&map, GL_SRGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, NeverSupported, AlwaysSupported);
AddRGBAFormat(&map, GL_SRGB_ALPHA_EXT, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, RequireExt<&Extensions::sRGB>, AlwaysSupported); AddRGBAFormat(&map, GL_SRGB_ALPHA_EXT, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, RequireExt<&Extensions::sRGB>, AlwaysSupported);
...@@ -764,6 +768,8 @@ static InternalFormatInfoMap BuildInternalFormatInfoMap() ...@@ -764,6 +768,8 @@ static InternalFormatInfoMap BuildInternalFormatInfoMap()
AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> ); AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> ); AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
AddRGBAFormat(&map, GL_RGB, false, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, UnsizedFloatSupport, UnsizedFloatRGBRenderableSupport, RequireExt<&Extensions::textureFloatLinear> ); AddRGBAFormat(&map, GL_RGB, false, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, UnsizedFloatSupport, UnsizedFloatRGBRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
AddRGBAFormat(&map, GL_RGB, false, 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
AddRGBAFormat(&map, GL_RGB, false, 11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
AddRGBAFormat(&map, GL_RGBA, false, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, UnsizedFloatSupport, UnsizedFloatRGBARenderableSupport, RequireExt<&Extensions::textureFloatLinear> ); AddRGBAFormat(&map, GL_RGBA, false, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, UnsizedFloatSupport, UnsizedFloatRGBARenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
// Unsized luminance alpha formats // Unsized luminance alpha formats
......
...@@ -1170,7 +1170,7 @@ bool ValidImageDataSize(ValidationContext *context, ...@@ -1170,7 +1170,7 @@ bool ValidImageDataSize(ValidationContext *context,
GLsizei width, GLsizei width,
GLsizei height, GLsizei height,
GLsizei depth, GLsizei depth,
GLenum internalFormat, GLenum format,
GLenum type, GLenum type,
const void *pixels, const void *pixels,
GLsizei imageSize) GLsizei imageSize)
...@@ -1184,7 +1184,8 @@ bool ValidImageDataSize(ValidationContext *context, ...@@ -1184,7 +1184,8 @@ bool ValidImageDataSize(ValidationContext *context,
// ...the data would be unpacked from the buffer object such that the memory reads required // ...the data would be unpacked from the buffer object such that the memory reads required
// would exceed the data store size. // would exceed the data store size.
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat, type); const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format, type);
ASSERT(formatInfo.internalFormat != GL_NONE);
const gl::Extents size(width, height, depth); const gl::Extents size(width, height, depth);
const auto &unpack = context->getGLState().getUnpackState(); const auto &unpack = context->getGLState().getUnpackState();
......
...@@ -65,7 +65,7 @@ bool ValidImageDataSize(ValidationContext *context, ...@@ -65,7 +65,7 @@ bool ValidImageDataSize(ValidationContext *context,
GLsizei width, GLsizei width,
GLsizei height, GLsizei height,
GLsizei depth, GLsizei depth,
GLenum internalFormat, GLenum format,
GLenum type, GLenum type,
const void *pixels, const void *pixels,
GLsizei imageSize); GLsizei imageSize);
......
...@@ -1336,7 +1336,8 @@ bool ValidateES2TexImageParameters(Context *context, ...@@ -1336,7 +1336,8 @@ bool ValidateES2TexImageParameters(Context *context,
} }
} }
if (!ValidImageDataSize(context, target, width, height, 1, internalformat, type, pixels, GLenum sizeCheckFormat = isSubImage ? format : internalformat;
if (!ValidImageDataSize(context, target, width, height, 1, sizeCheckFormat, type, pixels,
imageSize)) imageSize))
{ {
return false; return false;
......
...@@ -296,8 +296,9 @@ bool ValidateES3TexImageParametersBase(Context *context, ...@@ -296,8 +296,9 @@ bool ValidateES3TexImageParametersBase(Context *context,
} }
} }
if (!ValidImageDataSize(context, target, width, height, depth, actualInternalFormat, type, GLenum sizeCheckFormat = isSubImage ? format : internalformat;
pixels, imageSize)) if (!ValidImageDataSize(context, target, width, height, depth, sizeCheckFormat, type, pixels,
imageSize))
{ {
return false; return false;
} }
......
...@@ -304,7 +304,7 @@ TEST_P(RobustClientMemoryTest, GetInteger) ...@@ -304,7 +304,7 @@ TEST_P(RobustClientMemoryTest, GetInteger)
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
} }
// Test basic usage and validation of glTexImage2DRobustANGLE // Test basic usage and validation of glTexImage2DRobustANGLE and glTexSubImage2DRobustANGLE
TEST_P(RobustClientMemoryTest, TexImage2D) TEST_P(RobustClientMemoryTest, TexImage2D)
{ {
if (!extensionsPresent()) if (!extensionsPresent())
...@@ -323,12 +323,22 @@ TEST_P(RobustClientMemoryTest, TexImage2D) ...@@ -323,12 +323,22 @@ TEST_P(RobustClientMemoryTest, TexImage2D)
rgbaData.data()); rgbaData.data());
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
glTexSubImage2DRobustANGLE(GL_TEXTURE_2D, 0, 0, 0, dataDimension, dataDimension, GL_RGBA,
GL_UNSIGNED_BYTE, static_cast<GLsizei>(rgbaData.size()),
rgbaData.data());
EXPECT_GL_NO_ERROR();
// Test with a data size that is too small // Test with a data size that is too small
glTexImage2DRobustANGLE(GL_TEXTURE_2D, 0, GL_RGBA, dataDimension, dataDimension, 0, GL_RGBA, glTexImage2DRobustANGLE(GL_TEXTURE_2D, 0, GL_RGBA, dataDimension, dataDimension, 0, GL_RGBA,
GL_UNSIGNED_BYTE, static_cast<GLsizei>(rgbaData.size()) / 2, GL_UNSIGNED_BYTE, static_cast<GLsizei>(rgbaData.size()) / 2,
rgbaData.data()); rgbaData.data());
EXPECT_GL_ERROR(GL_INVALID_OPERATION); EXPECT_GL_ERROR(GL_INVALID_OPERATION);
glTexSubImage2DRobustANGLE(GL_TEXTURE_2D, 0, 0, 0, dataDimension, dataDimension, GL_RGBA,
GL_UNSIGNED_BYTE, static_cast<GLsizei>(rgbaData.size()) / 2,
rgbaData.data());
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
if (getClientMajorVersion() >= 3) if (getClientMajorVersion() >= 3)
{ {
// Set an unpack parameter that would cause the driver to read past the end of the buffer // Set an unpack parameter that would cause the driver to read past the end of the buffer
......
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