Bug 238134 - Validate readpixels format and type inside of WebCore
Summary: Validate readpixels format and type inside of WebCore
Status: ASSIGNED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: John Cunningham
URL:
Keywords: InRadar
Depends on: 239114
Blocks:
  Show dependency treegraph
 
Reported: 2022-03-21 00:55 PDT by John Cunningham
Modified: 2022-06-01 15:54 PDT (History)
12 users (show)

See Also:


Attachments
Patch (4.08 KB, patch)
2022-03-21 00:56 PDT, John Cunningham
no flags Details | Formatted Diff | Diff
Patch (6.33 KB, patch)
2022-03-21 17:48 PDT, John Cunningham
no flags Details | Formatted Diff | Diff
Patch (6.38 KB, patch)
2022-03-21 17:52 PDT, John Cunningham
no flags Details | Formatted Diff | Diff
Patch (6.43 KB, patch)
2022-03-22 09:25 PDT, John Cunningham
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Cunningham 2022-03-21 00:55:47 PDT
Validate readpixels against UNSIGNED_INT_24_8 type and DEPTH_COMPONENT format
Comment 1 John Cunningham 2022-03-21 00:56:27 PDT
Created attachment 455221 [details]
Patch
Comment 2 John Cunningham 2022-03-21 00:57:34 PDT
webgl/2.0.y/conformance/reading/read-pixels-test.html now passes in entirety.
Comment 3 EWS Watchlist 2022-03-21 00:57:45 PDT
Note that there are important steps to take when updating ANGLE. See https://trac.webkit.org/wiki/UpdatingANGLE
Comment 4 John Cunningham 2022-03-21 17:48:47 PDT
Created attachment 455308 [details]
Patch
Comment 5 John Cunningham 2022-03-21 17:52:46 PDT
Created attachment 455310 [details]
Patch
Comment 6 Myles C. Maxfield 2022-03-21 18:06:41 PDT
Comment on attachment 455310 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=455310&action=review

> Source/WebCore/ChangeLog:3
> +        Validate readpixels format and type inside of WebCore

Silly question: Why doesn't ANGLE validate this for us?
Comment 7 John Cunningham 2022-03-22 09:25:09 PDT
Created attachment 455380 [details]
Patch
Comment 8 Kenneth Russell 2022-03-22 10:33:25 PDT
Comment on attachment 455380 [details]
Patch

Just FYI: ANGLE does do this validation. The only validation that should be needed at the WebCore level is to ensure that the incoming typed array type is compatible with the format being requested in readPixels. See Chromium's associated validation:

https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc;l=4568
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/webgl/webgl2_rendering_context_base.cc;l=5608
Comment 9 John Cunningham 2022-03-22 10:42:48 PDT
(In reply to Kenneth Russell from comment #8)
> Comment on attachment 455380 [details]
> Patch
> 
> Just FYI: ANGLE does do this validation. The only validation that should be
> needed at the WebCore level is to ensure that the incoming typed array type
> is compatible with the format being requested in readPixels. See Chromium's
> associated validation:
> 
> https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/
> renderer/modules/webgl/webgl_rendering_context_base.cc;l=4568
> https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/
> renderer/modules/webgl/webgl2_rendering_context_base.cc;l=5608

Thanks, Ken. My original patch here was on ANGLE. It seems there are two things going on:

1. ANGLE's readpixel validation allows UNSIGNED_INT_24_8, which does not seem to be accurate to my spec reading.

2. ANGLE's readpixel validation early outs for read-pixels-test.html because of a missing attachment which is undefined behavior, see these lines in validationES.cpp

if (readBuffer == nullptr)
{
    context->validationError(entryPoint, GL_INVALID_OPERATION, kMissingReadAttachment);
    return false;
}

I'm happy to fix the first in upstream ANGLE, and fix the undefined behavior in the test which is causing it to fail. I wonder if it still makes sense to swap the order of the undefined behavior check of missing attachment to after the pixel/type validation in ANGLE.
Comment 10 Kenneth Russell 2022-03-22 11:47:14 PDT
(In reply to John Cunningham from comment #9)
> (In reply to Kenneth Russell from comment #8)
> > Comment on attachment 455380 [details]
> > Patch
> > 
> > Just FYI: ANGLE does do this validation. The only validation that should be
> > needed at the WebCore level is to ensure that the incoming typed array type
> > is compatible with the format being requested in readPixels. See Chromium's
> > associated validation:
> > 
> > https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/
> > renderer/modules/webgl/webgl_rendering_context_base.cc;l=4568
> > https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/
> > renderer/modules/webgl/webgl2_rendering_context_base.cc;l=5608
> 
> Thanks, Ken. My original patch here was on ANGLE. It seems there are two
> things going on:
> 
> 1. ANGLE's readpixel validation allows UNSIGNED_INT_24_8, which does not
> seem to be accurate to my spec reading.
> 
> 2. ANGLE's readpixel validation early outs for read-pixels-test.html because
> of a missing attachment which is undefined behavior, see these lines in
> validationES.cpp
> 
> if (readBuffer == nullptr)
> {
>     context->validationError(entryPoint, GL_INVALID_OPERATION,
> kMissingReadAttachment);
>     return false;
> }
> 
> I'm happy to fix the first in upstream ANGLE, and fix the undefined behavior
> in the test which is causing it to fail. I wonder if it still makes sense to
> swap the order of the undefined behavior check of missing attachment to
> after the pixel/type validation in ANGLE.

Thanks for the confirmation; I see.

For (1), it sounds fine to look into fixing this in ANGLE; but the bug is in Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp, WebGLRenderingContextBase::validateArrayBufferType. The case for GraphicsContextGL::UNSIGNED_INT_24_8 should just be removed; then that part of the test will pass.

Not sure about the second bug though. Happy to discuss further.
Comment 11 Kenneth Russell 2022-03-22 18:09:25 PDT
After further discussion on Slack, I see that the existing validateArrayBufferType is used for both Tex{Sub}Image and ReadPixels operations.

Still - would you consider passing an additional parameter to validateArrayBufferType, whether it's for ReadPixels or not? Then it could reject UNSIGNED_INT_24_8 for ReadPixels and avoid duplicating this code.
Comment 12 Radar WebKit Bug Importer 2022-03-28 00:56:16 PDT
<rdar://problem/90910118>
Comment 13 Kimmo Kinnunen 2022-04-11 23:45:55 PDT
Landed in ANGLE upstream:
https://bugs.chromium.org/p/angleproject/issues/detail?id=7119
Comment 14 Kenneth Russell 2022-04-26 16:22:35 PDT
Should roll into WebKit in Bug 239114.
Comment 15 Ahmad Saleem 2022-06-01 15:54:34 PDT
I think this bug can be closed (if scope is just update of ANGLE library) since it was within ANGLE library and it was updated as mentioned in Comment 13. But, from Comment 10 to remove a case bit within "Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp", I noticed from Webkit Github mirror that it is still present on line 5504.

Webkit Mirror file link - https://github.com/WebKit/WebKit/blob/2e84b9750f8c04ed405b84e8fbfb2dbc0bf24497/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp

Thanks!