Changeset 75175 in webkit


Ignore:
Timestamp:
Jan 6, 2011 11:33:58 AM (13 years ago)
Author:
zmo@google.com
Message:

2010-12-28 Zhenyao Mo <zmo@google.com>

Reviewed by Kenneth Russell.

Must generate INVALID_VALUE errors for strings containing out-of-range characters
https://bugs.webkit.org/show_bug.cgi?id=50929

  • html/canvas/WebGLRenderingContext.cpp: Validate characters according to GLSL ES 1.0 spec section 3.1. (WebCore::WebGLRenderingContext::bindAttribLocation): (WebCore::WebGLRenderingContext::getAttribLocation): (WebCore::WebGLRenderingContext::getUniformLocation): (WebCore::WebGLRenderingContext::shaderSource): (WebCore::WebGLRenderingContext::validateString): Helper function to perform the character validation.
  • html/canvas/WebGLRenderingContext.h: Declare validateString().

2010-12-28 Zhenyao Mo <zmo@google.com>

Reviewed by Kenneth Russell.

Must generate INVALID_VALUE errors for strings containing out-of-range characters
https://bugs.webkit.org/show_bug.cgi?id=50929

  • fast/canvas/webgl/invalid-passed-params-expected.txt: Add test cases for invalid characters.
  • fast/canvas/webgl/invalid-passed-params.html: Ditto.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r75173 r75175  
     12010-12-28  Zhenyao Mo  <zmo@google.com>
     2
     3        Reviewed by Kenneth Russell.
     4
     5        Must generate INVALID_VALUE errors for strings containing out-of-range characters
     6        https://bugs.webkit.org/show_bug.cgi?id=50929
     7
     8        * fast/canvas/webgl/invalid-passed-params-expected.txt: Add test cases for invalid characters.
     9        * fast/canvas/webgl/invalid-passed-params.html: Ditto.
     10
    1112011-01-06  Abhishek Arya  <inferno@chromium.org>
    212
  • trunk/LayoutTests/fast/canvas/webgl/invalid-passed-params-expected.txt

    r74719 r75175  
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
     4
    45
    56Test createShader()
     
    89PASS context.createShader(0) generated expected GL error: INVALID_ENUM.
    910PASS context.createShader(context.TRIANGLES) generated expected GL error: INVALID_ENUM.
     11
    1012Test clear()
    1113PASS context.clear(desktopGL['ACCUM_BUFFER_BIT']) generated expected GL error: INVALID_VALUE.
     
    1315PASS context.clear(desktopGL['ACCUM_BUFFER_BIT'] | context.COLOR_BUFFER_BIT | context.DEPTH_BUFFER_BIT | context.STENCIL_BUFFER_BIT) generated expected GL error: INVALID_VALUE.
    1416PASS context.clear(context.COLOR_BUFFER_BIT | context.DEPTH_BUFFER_BIT | context.STENCIL_BUFFER_BIT) generated expected GL error: NO_ERROR.
     17
    1518Test bufferData()
    1619PASS context.bindBuffer(context.ARRAY_BUFFER, buffer) generated expected GL error: NO_ERROR.
     
    2427PASS context.bufferData(context.ARRAY_BUFFER, 16, desktopGL['DYNAMIC_READ']) generated expected GL error: INVALID_ENUM.
    2528PASS context.bufferData(context.ARRAY_BUFFER, 16, desktopGL['DYNAMIC_COPY']) generated expected GL error: INVALID_ENUM.
     29
    2630Test {copy}Tex{Sub}Image2D with negative offset/width/height
    2731PASS context.bindTexture(context.TEXTURE_2D, tex) generated expected GL error: NO_ERROR.
     
    3640PASS context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, 0, 0, -1, -1) generated expected GL error: INVALID_VALUE.
    3741PASS context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2) generated expected GL error: NO_ERROR.
     42
    3843Test renderbufferStorage() with negative width/height
    3944PASS context.bindRenderbuffer(context.RENDERBUFFER, renderbuffer) generated expected GL error: NO_ERROR.
    4045PASS context.renderbufferStorage(context.RENDERBUFFER, context.RGBA4, -2, -2) generated expected GL error: INVALID_VALUE.
    4146PASS context.renderbufferStorage(context.RENDERBUFFER, context.RGBA4, 16, 16) generated expected GL error: NO_ERROR.
     47
    4248Test scissor() with negative width/height
    4349PASS context.scissor(0, 0, -2, -2) generated expected GL error: INVALID_VALUE.
    4450PASS context.scissor(0, 0, 16, 16) generated expected GL error: NO_ERROR.
     51
    4552Test viewport() with negative width/height
    4653PASS context.viewport(0, 0, -2, -2) generated expected GL error: INVALID_VALUE.
    4754PASS context.viewport(0, 0, 16, 16) generated expected GL error: NO_ERROR.
     55
     56Set up a program to test invalid characters
     57PASS context.getError() is context.NO_ERROR
     58PASS context.getError() is context.NO_ERROR
     59PASS context.getProgramParameter(program, context.LINK_STATUS) is true
     60PASS context.getError() is context.NO_ERROR
     61PASS context.getError() is context.NO_ERROR
     62PASS context.getError() is context.NO_ERROR
     63PASS context.getError() is context.NO_ERROR
     64
     65Test shaderSource() with invalid characters
     66PASS context.getError() is context.INVALID_VALUE
     67PASS context.getError() is context.INVALID_VALUE
     68PASS context.getError() is context.INVALID_VALUE
     69PASS context.getError() is context.INVALID_VALUE
     70PASS context.getError() is context.INVALID_VALUE
     71PASS context.getError() is context.INVALID_VALUE
     72
     73Test bindAttribLocation() with invalid characters
     74PASS context.getError() is context.INVALID_VALUE
     75PASS context.getError() is context.INVALID_VALUE
     76PASS context.getError() is context.INVALID_VALUE
     77PASS context.getError() is context.INVALID_VALUE
     78PASS context.getError() is context.INVALID_VALUE
     79PASS context.getError() is context.INVALID_VALUE
     80
     81Test getAttribLocation() with invalid characters
     82PASS context.getError() is context.INVALID_VALUE
     83PASS context.getError() is context.INVALID_VALUE
     84PASS context.getError() is context.INVALID_VALUE
     85PASS context.getError() is context.INVALID_VALUE
     86PASS context.getError() is context.INVALID_VALUE
     87PASS context.getError() is context.INVALID_VALUE
     88
     89Test getUniformLocation() with invalid characters
     90PASS context.getError() is context.INVALID_VALUE
     91PASS context.getError() is context.INVALID_VALUE
     92PASS context.getError() is context.INVALID_VALUE
     93PASS context.getError() is context.INVALID_VALUE
     94PASS context.getError() is context.INVALID_VALUE
     95PASS context.getError() is context.INVALID_VALUE
    4896
    4997PASS successfullyParsed is true
  • trunk/LayoutTests/fast/canvas/webgl/invalid-passed-params.html

    r74719 r75175  
    1515var context = create3DContext();
    1616
     17debug("");
    1718debug("Test createShader()");
    1819shouldGenerateGLError(context, context.NO_ERROR, "context.createShader(context.FRAGMENT_SHADER)");
     
    2122shouldGenerateGLError(context, context.INVALID_ENUM, "context.createShader(context.TRIANGLES)");
    2223
     24debug("");
    2325debug("Test clear()");
    2426shouldGenerateGLError(context, context.INVALID_VALUE, "context.clear(desktopGL['ACCUM_BUFFER_BIT'])");
     
    2729shouldGenerateGLError(context, context.NO_ERROR, "context.clear(context.COLOR_BUFFER_BIT | context.DEPTH_BUFFER_BIT | context.STENCIL_BUFFER_BIT)");
    2830
     31debug("");
    2932debug("Test bufferData()");
    3033var buffer = context.createBuffer();
     
    4043shouldGenerateGLError(context, context.INVALID_ENUM, "context.bufferData(context.ARRAY_BUFFER, 16, desktopGL['DYNAMIC_COPY'])");
    4144
     45debug("");
    4246debug("Test {copy}Tex{Sub}Image2D with negative offset/width/height");
    4347var tex = context.createTexture();
     
    5559shouldGenerateGLError(context, context.NO_ERROR, "context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2)");
    5660
     61debug("");
    5762debug("Test renderbufferStorage() with negative width/height");
    5863var renderbuffer = context.createRenderbuffer();
     
    6166shouldGenerateGLError(context, context.NO_ERROR, "context.renderbufferStorage(context.RENDERBUFFER, context.RGBA4, 16, 16)");
    6267
     68debug("");
    6369debug("Test scissor() with negative width/height");
    6470shouldGenerateGLError(context, context.INVALID_VALUE, "context.scissor(0, 0, -2, -2)");
    6571shouldGenerateGLError(context, context.NO_ERROR, "context.scissor(0, 0, 16, 16)");
    6672
     73debug("");
    6774debug("Test viewport() with negative width/height");
    6875shouldGenerateGLError(context, context.INVALID_VALUE, "context.viewport(0, 0, -2, -2)");
    6976shouldGenerateGLError(context, context.NO_ERROR, "context.viewport(0, 0, 16, 16)");
     77
     78debug("");
     79debug("Set up a program to test invalid characters");
     80var invalidSet = ['"', '$', '`', '@', '\\', "'"];
     81var validUniformName = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890";
     82var validAttribName = "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
     83var validShaderSource = "uniform float " + validUniformName + ";\n"
     84                        + "varying float " + validAttribName + ";\n"
     85                        + "void main() {\n"
     86                        + validAttribName  + " = " + validUniformName + ";\n"
     87                        + "gl_Position = vec4(0.0, 0.0, 0.0, 1.0); }\n";
     88                        + "//.+-/*%<>[](){}^|&~=!:;,?# ";
     89var vShader = context.createShader(context.VERTEX_SHADER);
     90context.shaderSource(vShader, validShaderSource);
     91context.compileShader(vShader);
     92shouldBe("context.getError()", "context.NO_ERROR");
     93var fShader = context.createShader(context.FRAGMENT_SHADER);
     94context.shaderSource(fShader, "precision highp float;\n"
     95                              + "varying float " + validAttribName + ";\n"
     96                              + "void main() {\n"
     97                              + "gl_FragColor = vec4(" + validAttribName + ", 0.0, 0.0, 1.0); }");
     98context.compileShader(fShader);
     99shouldBe("context.getError()", "context.NO_ERROR");
     100var program = context.createProgram();
     101context.attachShader(program, vShader);
     102context.attachShader(program, fShader);
     103context.linkProgram(program);
     104shouldBeTrue("context.getProgramParameter(program, context.LINK_STATUS)");
     105shouldBe("context.getError()", "context.NO_ERROR");
     106context.bindAttribLocation(program, 1, validAttribName);
     107shouldBe("context.getError()", "context.NO_ERROR");
     108context.getAttribLocation(program, validAttribName);
     109shouldBe("context.getError()", "context.NO_ERROR");
     110context.getUniformLocation(program, validUniformName);
     111shouldBe("context.getError()", "context.NO_ERROR");
     112
     113debug("");
     114debug("Test shaderSource() with invalid characters");
     115for (var i = 0; i < invalidSet.length; ++i) {
     116  var invalidShaderSource = validShaderSource + "\n//" + invalidSet[i];
     117  context.shaderSource(vShader, invalidShaderSource);
     118  shouldBe("context.getError()", "context.INVALID_VALUE");
     119}
     120
     121debug("");
     122debug("Test bindAttribLocation() with invalid characters");
     123for (var i = 0; i < invalidSet.length; ++i) {
     124  var invalidName = validAttribName + invalidSet[i];
     125  context.bindAttribLocation(program, 1, invalidName);
     126  shouldBe("context.getError()", "context.INVALID_VALUE");
     127}
     128
     129debug("");
     130debug("Test getAttribLocation() with invalid characters");
     131for (var i = 0; i < invalidSet.length; ++i) {
     132  var invalidName = validAttribName + invalidSet[i];
     133  context.getAttribLocation(program, invalidName);
     134  shouldBe("context.getError()", "context.INVALID_VALUE");
     135}
     136
     137debug("");
     138debug("Test getUniformLocation() with invalid characters");
     139for (var i = 0; i < invalidSet.length; ++i) {
     140  var invalidName = validUniformName + invalidSet[i];
     141  context.getUniformLocation(program, invalidName);
     142  shouldBe("context.getError()", "context.INVALID_VALUE");
     143}
    70144
    71145debug("")
  • trunk/WebCore/ChangeLog

    r75172 r75175  
     12010-12-28  Zhenyao Mo  <zmo@google.com>
     2
     3        Reviewed by Kenneth Russell.
     4
     5        Must generate INVALID_VALUE errors for strings containing out-of-range characters
     6        https://bugs.webkit.org/show_bug.cgi?id=50929
     7
     8        * html/canvas/WebGLRenderingContext.cpp: Validate characters according to GLSL ES 1.0 spec section 3.1.
     9        (WebCore::WebGLRenderingContext::bindAttribLocation):
     10        (WebCore::WebGLRenderingContext::getAttribLocation):
     11        (WebCore::WebGLRenderingContext::getUniformLocation):
     12        (WebCore::WebGLRenderingContext::shaderSource):
     13        (WebCore::WebGLRenderingContext::validateString): Helper function to perform the character validation.
     14        * html/canvas/WebGLRenderingContext.h: Declare validateString().
     15
    1162011-01-06  Yong Li  <yoli@rim.com>
    217
  • trunk/WebCore/html/canvas/WebGLRenderingContext.cpp

    r74818 r75175  
    8787    }
    8888
     89    // Return true if a character belongs to the ASCII subset as defined in
     90    // GLSL ES 1.0 spec section 3.1.
     91    bool validateCharacter(unsigned char c)
     92    {
     93        // Printing characters are valid except " $ ` @ \ ' DEL.
     94        if (c >= 32 && c <= 126
     95            && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' && c != '\'')
     96            return true;
     97        // Horizontal tab, line feed, vertical tab, form feed, carriage return
     98        // are also valid.
     99        if (c >= 9 && c <= 13)
     100            return true;
     101        return false;
     102    }
     103
    89104} // namespace anonymous
    90105
     
    311326    if (isContextLost() || !validateWebGLObject(program))
    312327        return;
     328    if (!validateString(name))
     329        return;
    313330    m_context->bindAttribLocation(objectOrZero(program), index, name);
    314331    cleanupAfterGraphicsCall(false);
     
    14601477{
    14611478    if (isContextLost())
     1479        return -1;
     1480    if (!validateString(name))
    14621481        return -1;
    14631482    return m_context->getAttribLocation(objectOrZero(program), name);
     
    20862105    if (isContextLost() || !validateWebGLObject(program))
    20872106        return 0;
     2107    if (!validateString(name))
     2108        return 0;
    20882109    WebGLStateRestorer(this, false);
    20892110    long uniformLocation = m_context->getUniformLocation(objectOrZero(program), name);
     
    24702491    if (isContextLost() || !validateWebGLObject(shader))
    24712492        return;
     2493    if (!validateString(string))
     2494        return;
    24722495    m_context->shaderSource(objectOrZero(shader), string);
    24732496    cleanupAfterGraphicsCall(false);
     
    37053728}
    37063729
     3730bool WebGLRenderingContext::validateString(const String& string)
     3731{
     3732    for (size_t i = 0; i < string.length(); ++i) {
     3733        if (!validateCharacter(string[i])) {
     3734            m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE);
     3735            return false;
     3736        }
     3737    }
     3738    return true;
     3739}
     3740
    37073741bool WebGLRenderingContext::validateTexFuncFormatAndType(unsigned long format, unsigned long type)
    37083742{
  • trunk/WebCore/html/canvas/WebGLRenderingContext.h

    r74818 r75175  
    516516    bool validateSize(long x, long y);
    517517
     518    // Helper function to check if all characters in the string belong to the
     519    // ASCII subset as defined in GLSL ES 1.0 spec section 3.1.
     520    bool validateString(const String&);
     521
    518522    // Helper function to check target and texture bound to the target.
    519523    // Generate GL errors and return 0 if target is invalid or texture bound is
Note: See TracChangeset for help on using the changeset viewer.