Commit fb05264b by Geoff Lang Committed by Commit Bot

Disallow null pixel data for TexSubImage that have non-zero size.

BUG=angleproject:2055 Change-Id: I4c338691776c6d807333c169ed876d686188a97c Reviewed-on: https://chromium-review.googlesource.com/735786Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent c9727f31
...@@ -133,6 +133,7 @@ ERRMSG(OffsetMustBeMultipleOfType, "Offset must be a multiple of the passed in d ...@@ -133,6 +133,7 @@ ERRMSG(OffsetMustBeMultipleOfType, "Offset must be a multiple of the passed in d
ERRMSG(OutsideOfBounds, "Parameter outside of bounds."); ERRMSG(OutsideOfBounds, "Parameter outside of bounds.");
ERRMSG(ParamOverflow, "The provided parameters overflow with the provided buffer."); ERRMSG(ParamOverflow, "The provided parameters overflow with the provided buffer.");
ERRMSG(PixelDataNotNull, "Pixel data must be null."); ERRMSG(PixelDataNotNull, "Pixel data must be null.");
ERRMSG(PixelDataNull, "Pixel data cannot be null.");
ERRMSG(ProgramDoesNotExist, "Program doesn't exist."); ERRMSG(ProgramDoesNotExist, "Program doesn't exist.");
ERRMSG(ProgramNotBound, "A program must be bound."); ERRMSG(ProgramNotBound, "A program must be bound.");
ERRMSG(ProgramNotLinked, "Program not linked."); ERRMSG(ProgramNotLinked, "Program not linked.");
......
...@@ -1140,6 +1140,13 @@ bool ValidateES2TexImageParameters(Context *context, ...@@ -1140,6 +1140,13 @@ bool ValidateES2TexImageParameters(Context *context,
context->handleError(InvalidValue()); context->handleError(InvalidValue());
return false; return false;
} }
if (width > 0 && height > 0 && pixels == nullptr &&
context->getGLState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER) == nullptr)
{
ANGLE_VALIDATION_ERR(context, InvalidValue(), PixelDataNull);
return false;
}
} }
else else
{ {
......
...@@ -428,6 +428,13 @@ bool ValidateES3TexImageParametersBase(Context *context, ...@@ -428,6 +428,13 @@ bool ValidateES3TexImageParametersBase(Context *context,
context->handleError(InvalidValue()); context->handleError(InvalidValue());
return false; return false;
} }
if (width > 0 && height > 0 && depth > 0 && pixels == nullptr &&
context->getGLState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER) == nullptr)
{
ANGLE_VALIDATION_ERR(context, InvalidValue(), PixelDataNull);
return false;
}
} }
GLenum sizeCheckFormat = isSubImage ? format : internalformat; GLenum sizeCheckFormat = isSubImage ? format : internalformat;
......
...@@ -1727,15 +1727,6 @@ TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE) ...@@ -1727,15 +1727,6 @@ TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect. // ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
TEST_P(Texture2DTest, NPOTSubImageParameters) TEST_P(Texture2DTest, NPOTSubImageParameters)
{ {
// TODO(geofflang): Allow the GL backend to accept SubImage calls with a null data ptr. (bug
// 1278)
if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
{
std::cout << "Test disabled on OpenGL." << std::endl;
return;
}
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, mTexture2D); glBindTexture(GL_TEXTURE_2D, mTexture2D);
...@@ -1747,7 +1738,8 @@ TEST_P(Texture2DTest, NPOTSubImageParameters) ...@@ -1747,7 +1738,8 @@ TEST_P(Texture2DTest, NPOTSubImageParameters)
// Supply a 3x3 (i.e. non-power-of-two) subimage to the texture. // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
// This should always work, even if GL_OES_texture_npot isn't active. // This should always work, even if GL_OES_texture_npot isn't active.
glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); std::array<GLColor, 3 * 3> data;
glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
} }
......
...@@ -1107,6 +1107,47 @@ TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBufferEvenNotUsedOnes) ...@@ -1107,6 +1107,47 @@ TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBufferEvenNotUsedOnes)
EXPECT_GL_ERROR(GL_INVALID_OPERATION); EXPECT_GL_ERROR(GL_INVALID_OPERATION);
} }
// Test that passing a null pixel data pointer to TexSubImage calls generates an INVALID_VALUE error
TEST_P(WebGLCompatibilityTest, NullPixelDataForSubImage)
{
// glTexSubImage2D
{
GLTexture texture;
glBindTexture(GL_TEXTURE_2D, texture);
// TexImage with null data - OK
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
EXPECT_GL_NO_ERROR();
// TexSubImage with zero size and null data - OK
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
EXPECT_GL_NO_ERROR();
// TexSubImage with non-zero size and null data - Invalid value
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
}
// glTexSubImage3D
if (getClientMajorVersion() >= 3)
{
GLTexture texture;
glBindTexture(GL_TEXTURE_3D, texture);
// TexImage with null data - OK
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
EXPECT_GL_NO_ERROR();
// TexSubImage with zero size and null data - OK
glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
EXPECT_GL_NO_ERROR();
// TexSubImage with non-zero size and null data - Invalid value
glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
}
}
// Tests the WebGL requirement of having the same stencil mask, writemask and ref for fron and back // Tests the WebGL requirement of having the same stencil mask, writemask and ref for fron and back
TEST_P(WebGLCompatibilityTest, RequiresSameStencilMaskAndRef) TEST_P(WebGLCompatibilityTest, RequiresSameStencilMaskAndRef)
{ {
......
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