Commit 335d8bf2 by Bryan Bernhart (Intel Americas Inc) Committed by Commit Bot

WebGLCompatibility: Fix shader validation using define macros.

Backslash as line-continutation character is not permitted to be used within a pre-processor directive for WebGL1. BUG=angleproject:2093 Change-Id: I649a914b9bc544a3e4f9e7eff23b95a62c9b7008 Reviewed-on: https://chromium-review.googlesource.com/734218Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Bryan Bernhart <bryan.bernhart@intel.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent c4f1dd83
...@@ -919,8 +919,12 @@ bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinu ...@@ -919,8 +919,12 @@ bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinu
break; break;
case ParseState::IN_PREPROCESSOR_DIRECTIVE: case ParseState::IN_PREPROCESSOR_DIRECTIVE:
// No matter what the character is, just pass it // Line-continuation characters may not be permitted.
// through. Do not parse comments in this state. // Otherwise, just pass it through. Do not parse comments in this state.
if (!lineContinuationAllowed && c == '\\')
{
return false;
}
pos++; pos++;
break; break;
......
...@@ -1511,6 +1511,39 @@ TEST_P(WebGLCompatibilityTest, InvalidAttributeAndUniformNames) ...@@ -1511,6 +1511,39 @@ TEST_P(WebGLCompatibilityTest, InvalidAttributeAndUniformNames)
} }
// Test that line continuation is handled correctly when valdiating shader source // Test that line continuation is handled correctly when valdiating shader source
TEST_P(WebGLCompatibilityTest, ShaderSourceLineContinuation)
{
// Verify that a line continuation character (i.e. backslash) cannot be used
// within a preprocessor directive in a ES2 context.
ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
const char *validVert =
"#define foo this is a test\n"
"precision mediump float;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(1.0);\n"
"}\n";
const char *invalidVert =
"#define foo this \\n"
" is a test\n"
"precision mediump float;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(1.0);\n"
"}\n";
GLuint shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shader, 1, &validVert, nullptr);
EXPECT_GL_NO_ERROR();
glShaderSource(shader, 1, &invalidVert, nullptr);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
glDeleteShader(shader);
}
// Test that line continuation is handled correctly when valdiating shader source
TEST_P(WebGL2CompatibilityTest, ShaderSourceLineContinuation) TEST_P(WebGL2CompatibilityTest, ShaderSourceLineContinuation)
{ {
const char *validVert = const char *validVert =
......
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