Bug 98973

Summary: [CSS Shaders] Reject vertex shaders with custom attributes
Product: WebKit Reporter: Max Vujovic <mvujovic>
Component: Layout and RenderingAssignee: Max Vujovic <mvujovic>
Status: RESOLVED FIXED    
Severity: Normal CC: achicu, allan.jensen, cmarcelo, dglazkov, dino, eric, macpherson, menard, peter+ews, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 71392    
Attachments:
Description Flags
Patch
mvujovic: commit-queue-
Patch
webkit-ews: commit-queue-
Patch
mvujovic: commit-queue-
Patch
mvujovic: commit-queue-
Patch
mvujovic: commit-queue-
Patch
mvujovic: commit-queue-
Patch
mvujovic: commit-queue-
Patch
none
Patch none

Description Max Vujovic 2012-10-10 17:20:37 PDT
An author shouldn't be able to define custom vertex attributes because there is no way to set them from CSS.

For example, defining built-in attributes is ok:
attribute vec4 a_position;
attribute vec2 a_texCoord;

But defining custom attributes should be an error:
attribute float my_attribute;

Also, we have to be careful with attached vs. detached meshes. "a_triangleCoord" is available only in detached meshes.
Comment 1 Max Vujovic 2012-10-23 09:51:16 PDT
Created attachment 170183 [details]
Patch
Comment 2 Max Vujovic 2012-10-23 10:31:50 PDT
Comment on attachment 170183 [details]
Patch

In this patch, I still need to figure out how to get the meshType in CustomFilterValidatedProgram, since a_triangleCoord is a built-in attribute in detached meshes but not in attached meshes.
Comment 3 Max Vujovic 2012-10-25 16:15:06 PDT
Created attachment 170762 [details]
Patch

Now the patch uses the mesh type to check if a_triangleCoord is a valid attribute.
Comment 4 Early Warning System Bot 2012-10-25 16:24:34 PDT
Comment on attachment 170762 [details]
Patch

Attachment 170762 [details] did not pass qt-wk2-ews (qt):
Output: http://queues.webkit.org/results/14559802
Comment 5 Alexandru Chiculita 2012-10-25 16:50:03 PDT
View in context: https://bugs.webkit.org/attachment.cgi?id=170762&action=review

Looks good.

> LayoutTests/css3/filters/resources/invalid-a-triangle-coord-with-attached-mesh.vs:9
> +attribute vec3 a_triangleCoord;
> +
> +attribute vec4 a_position;
> +
> +uniform mat4 u_projectionMatrix;

Remove the empty lines.

> LayoutTests/css3/filters/resources/invalid-custom-attribute.vs:9
> +attribute float my_attribute;
> +
> +attribute vec4 a_position;
> +
> +uniform mat4 u_projectionMatrix;

Ditto.

> Source/WebCore/WebCore.xcodeproj/project.pbxproj:-3805
> -		A24A3A9D162499FF00522745 /* CustomFilterConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = A24A3A9C162499FF00522745 /* CustomFilterConstants.h */; };

I think you can revert the xcode changes.

> Source/WebCore/WebCore.xcodeproj/project.pbxproj:18251
> -				A24A3A9C162499FF00522745 /* CustomFilterConstants.h */,
> +				A2B2AE7B16375EE500CFA50B /* CustomFilterConstants.h */,

ditto

> Source/WebCore/WebCore.xcodeproj/project.pbxproj:22694
> -				A24A3A9D162499FF00522745 /* CustomFilterConstants.h in Headers */,
> +				A2B2AE7C16375EE500CFA50B /* CustomFilterConstants.h in Headers */,

ditto

> Source/WebCore/platform/graphics/filters/CustomFilterProgram.h:63
>      // StyleCustomFilterProgram has the only implementation for the following method. That means, it casts to StyleCustomFilterProgram
> -    // withouth checking the type. If you add another implementation, also add a mechanism to check for the correct type.
> +    // without checking the type. If you add another implementation, also add a mechanism to check for the correct type.

I think this comment is not needed anymore.

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:66
> +bool CustomFilterValidatedProgram::validateSymbols(const Vector<ANGLEShaderSymbol>& symbols)

Pass the mesh type as a parameter to keep this static.

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:80
> +            if (symbol.name == "a_triangleCoord" && m_programInfo.meshType() != MeshTypeDetached) {

Why use the != operator instead of == ? We just have two modes at this moment. 

nit: Put the fastest comparison first. It will avoid making the strcmp when not needed.
Comment 6 Peter Beverloo (cr-android ews) 2012-10-25 17:59:16 PDT
Comment on attachment 170762 [details]
Patch

Attachment 170762 [details] did not pass cr-android-ews (chromium-android):
Output: http://queues.webkit.org/results/14544827
Comment 7 WebKit Review Bot 2012-10-25 20:57:45 PDT
Comment on attachment 170762 [details]
Patch

Attachment 170762 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/14569838
Comment 8 Max Vujovic 2012-10-26 12:00:10 PDT
Created attachment 170979 [details]
Patch

Trying to fix Qt, Chromium EWS build errors.
Comment 9 Early Warning System Bot 2012-10-26 12:35:14 PDT
Comment on attachment 170979 [details]
Patch

Attachment 170979 [details] did not pass qt-wk2-ews (qt):
Output: http://queues.webkit.org/results/14611143
Comment 10 Max Vujovic 2012-10-26 13:48:19 PDT
Created attachment 170995 [details]
Patch

Qt EWS build fix attempt.
Comment 11 Early Warning System Bot 2012-10-26 13:53:05 PDT
Comment on attachment 170995 [details]
Patch

Attachment 170995 [details] did not pass qt-wk2-ews (qt):
Output: http://queues.webkit.org/results/14617118
Comment 12 Max Vujovic 2012-10-26 15:01:46 PDT
Created attachment 171023 [details]
Patch

Trying qt-wk2 again.
Comment 13 Early Warning System Bot 2012-10-26 15:10:21 PDT
Comment on attachment 171023 [details]
Patch

Attachment 171023 [details] did not pass qt-wk2-ews (qt):
Output: http://queues.webkit.org/results/14614172
Comment 14 Max Vujovic 2012-10-26 15:36:10 PDT
Created attachment 171029 [details]
Patch

Trying qt-wk2 again.
Comment 15 Max Vujovic 2012-10-26 16:34:18 PDT
Created attachment 171046 [details]
Patch

Updated ChangeLog descriptions.
Comment 16 Max Vujovic 2012-10-26 16:45:12 PDT
Thanks for the review, Alex!

(In reply to comment #5)
> View in context: https://bugs.webkit.org/attachment.cgi?id=170762&action=review
> 
> Looks good.
> 
> > LayoutTests/css3/filters/resources/invalid-a-triangle-coord-with-attached-mesh.vs:9
> > +attribute vec3 a_triangleCoord;
> > +
> > +attribute vec4 a_position;
> > +
> > +uniform mat4 u_projectionMatrix;
> 
> Remove the empty lines.

Done. It looks better without the empty lines. I've also removed the empty lines from the other shaders referenced by the test file.

> 
> > LayoutTests/css3/filters/resources/invalid-custom-attribute.vs:9
> > +attribute float my_attribute;
> > +
> > +attribute vec4 a_position;
> > +
> > +uniform mat4 u_projectionMatrix;
> 
> Ditto.

Done.

> 
> > Source/WebCore/WebCore.xcodeproj/project.pbxproj:-3805
> > -		A24A3A9D162499FF00522745 /* CustomFilterConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = A24A3A9C162499FF00522745 /* CustomFilterConstants.h */; };
> 
> I think you can revert the xcode changes.

I need this to fixing an incorrect path to CustomFilterConstants.h in the Xcode project. The project thinks the file is in platform/graphics, not platform/graphics/filters. I need to fix the reference so that StyleResolver.cpp can find CustomFilterConstants.h. 

> 
> > Source/WebCore/WebCore.xcodeproj/project.pbxproj:18251
> > -				A24A3A9C162499FF00522745 /* CustomFilterConstants.h */,
> > +				A2B2AE7B16375EE500CFA50B /* CustomFilterConstants.h */,
> 
> ditto
> 
> > Source/WebCore/WebCore.xcodeproj/project.pbxproj:22694
> > -				A24A3A9D162499FF00522745 /* CustomFilterConstants.h in Headers */,
> > +				A2B2AE7C16375EE500CFA50B /* CustomFilterConstants.h in Headers */,
> 
> ditto
> 
> > Source/WebCore/platform/graphics/filters/CustomFilterProgram.h:63
> >      // StyleCustomFilterProgram has the only implementation for the following method. That means, it casts to StyleCustomFilterProgram
> > -    // withouth checking the type. If you add another implementation, also add a mechanism to check for the correct type.
> > +    // without checking the type. If you add another implementation, also add a mechanism to check for the correct type.
> 
> I think this comment is not needed anymore.

Removed. You're right.

> 
> > Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:66
> > +bool CustomFilterValidatedProgram::validateSymbols(const Vector<ANGLEShaderSymbol>& symbols)
> 
> Pass the mesh type as a parameter to keep this static.

Done.

> 
> > Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:80
> > +            if (symbol.name == "a_triangleCoord" && m_programInfo.meshType() != MeshTypeDetached) {
> 
> Why use the != operator instead of == ? We just have two modes at this moment. 

Done. I was using a whitelist approach (only allow a_triangleCoord in detached meshes) vs. a blacklist approach (don't allow a_triangleCoord in attached meshes). However, since we only have two mesh types right now, it's easier to read with the blacklist approach.

> 
> nit: Put the fastest comparison first. It will avoid making the strcmp when not needed.

Done. I was assuming most of the time people will be using attached meshes. If that's true, the original arrangement is faster. However, I can't back that up with any data, so I'll put the faster comparison first :)
Comment 17 Max Vujovic 2012-10-29 11:56:52 PDT
Comment on attachment 171046 [details]
Patch

Setting cq-. I need to rebase the patch.
Comment 18 Max Vujovic 2012-10-29 13:53:07 PDT
Created attachment 171303 [details]
Patch

Rebased patch.
Comment 19 Max Vujovic 2012-10-29 13:56:12 PDT
Created attachment 171306 [details]
Patch

Rebased patch v2. I had a merge issue in the previous one.
Comment 20 WebKit Review Bot 2012-10-30 06:21:41 PDT
Comment on attachment 171306 [details]
Patch

Clearing flags on attachment: 171306

Committed r132903: <http://trac.webkit.org/changeset/132903>
Comment 21 WebKit Review Bot 2012-10-30 06:21:46 PDT
All reviewed patches have been landed.  Closing bug.
Comment 22 Max Vujovic 2012-10-30 09:03:32 PDT
Thanks for the review, Dean!