Bug 39704 - readPixels with negative width/height should generate INVALID_VALUE and return
Summary: readPixels with negative width/height should generate INVALID_VALUE and return
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Zhenyao Mo
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-25 17:54 PDT by Zhenyao Mo
Modified: 2010-06-11 08:03 PDT (History)
5 users (show)

See Also:


Attachments
patch (11.06 KB, patch)
2010-05-25 19:20 PDT, Zhenyao Mo
no flags Details | Formatted Diff | Diff
patch (9.72 KB, patch)
2010-06-10 15:28 PDT, Zhenyao Mo
no flags Details | Formatted Diff | Diff
revised patch: responding to kbr's review (10.56 KB, patch)
2010-06-10 17:50 PDT, Zhenyao Mo
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zhenyao Mo 2010-05-25 17:54:00 PDT
Currently readPixels will crash if width/height are negative.  Instead, INVALID_VALUE should be generated.
Comment 1 Zhenyao Mo 2010-05-25 17:58:27 PDT
Also, with very large width/height and WebGL*Array creation failure, a INVALID_VALUE error will generate.
Comment 2 Zhenyao Mo 2010-05-25 19:20:04 PDT
Created attachment 57063 [details]
patch
Comment 3 David Levin 2010-05-26 14:15:37 PDT
What bug is this new line fixing?

 1707     memset(data, 0, totalBytes);

And does the layout test cover that? (If not, can it be added?)
Comment 4 Zhenyao Mo 2010-05-26 14:34:56 PDT
(In reply to comment #3)
> What bug is this new line fixing?
> 
>  1707     memset(data, 0, totalBytes);
> 
> And does the layout test cover that? (If not, can it be added?)

This is not a bug fix.  For safety reason, we clear the buffer so users will not get access to content they should not.  According to GLES spec, for the un-covered portion of the memory, their content is un-defined.  I don't think we should write a definitive test against something undefined, because whatever the content is, it should not be "incorrect".
Comment 5 David Levin 2010-05-26 14:40:14 PDT
(In reply to comment #4)
> (In reply to comment #3)
> > What bug is this new line fixing?
> > 
> >  1707     memset(data, 0, totalBytes);
> > 
> > And does the layout test cover that? (If not, can it be added?)
> 
> This is not a bug fix.  For safety reason, we clear the buffer so users will not get access to content they should not.  According to GLES spec, for the un-covered portion of the memory, their content is un-defined.  I don't think we should write a definitive test against something undefined, because whatever the content is, it should not be "incorrect".

Should it be set to something (like -10 for example) that is less likely to make users rely on undefined behavior?

0 tends to make things just work (that maybe shouldn't) and thus hide problems.
Comment 6 Oliver Hunt 2010-05-26 14:41:19 PDT
(In reply to comment #4)
> (In reply to comment #3)
> > What bug is this new line fixing?
> > 
> >  1707     memset(data, 0, totalBytes);
> > 
> > And does the layout test cover that? (If not, can it be added?)
> 
> This is not a bug fix.  For safety reason, we clear the buffer so users will not get access to content they should not.  According to GLES spec, for the un-covered portion of the memory, their content is un-defined.  I don't think we should write a definitive test against something undefined, because whatever the content is, it should not be "incorrect".


There should be a test, otherwise there's nothing to verify that the data is safe -- if some other implementation decides to produces something other than a zero-filled buffer they can add platform specific expected results.
Comment 7 Zhenyao Mo 2010-05-26 14:51:15 PDT
(In reply to comment #5)
> (In reply to comment #4)
> > (In reply to comment #3)
> > > What bug is this new line fixing?
> > > 
> > >  1707     memset(data, 0, totalBytes);
> > > 
> > > And does the layout test cover that? (If not, can it be added?)
> > 
> > This is not a bug fix.  For safety reason, we clear the buffer so users will not get access to content they should not.  According to GLES spec, for the un-covered portion of the memory, their content is un-defined.  I don't think we should write a definitive test against something undefined, because whatever the content is, it should not be "incorrect".
> 
> Should it be set to something (like -10 for example) that is less likely to make users rely on undefined behavior?
> 
> 0 tends to make things just work (that maybe shouldn't) and thus hide problems.

Good point.  I'll double check WebGL spec, if it doesn't have extra constraints about buffers initialized to 0, I'll use an odd number instead.
Comment 8 Zhenyao Mo 2010-05-26 14:51:57 PDT
(In reply to comment #6)
> (In reply to comment #4)
> > (In reply to comment #3)
> > > What bug is this new line fixing?
> > > 
> > >  1707     memset(data, 0, totalBytes);
> > > 
> > > And does the layout test cover that? (If not, can it be added?)
> > 
> > This is not a bug fix.  For safety reason, we clear the buffer so users will not get access to content they should not.  According to GLES spec, for the un-covered portion of the memory, their content is un-defined.  I don't think we should write a definitive test against something undefined, because whatever the content is, it should not be "incorrect".
> 
> 
> There should be a test, otherwise there's nothing to verify that the data is safe -- if some other implementation decides to produces something other than a zero-filled buffer they can add platform specific expected results.

Ok, will add a case then.
Comment 9 Zhenyao Mo 2010-05-26 15:07:44 PDT
ReadPixels signature will change.  This patch becomes invalid.
Comment 10 Zhenyao Mo 2010-06-10 15:24:25 PDT
Due to https://bugs.webkit.org/show_bug.cgi?id=40322, negative width/height will no longer cause crash, but still, we need to deal with it correctly, i.e., generate INVALID_VALUE and return.
Comment 11 Zhenyao Mo 2010-06-10 15:28:01 PDT
Created attachment 58418 [details]
patch
Comment 12 Kenneth Russell 2010-06-10 17:30:58 PDT
Comment on attachment 58418 [details]
patch

WebCore/html/canvas/WebGLRenderingContext.cpp:1673
 +      }
Let's put this check right after the NULL check for the "pixels" argument tomorrow to try to follow the request for prioritization of error returns from Mozilla:
https://www.khronos.org/webgl/public-mailing-list/archives/1006/msg00040.html


LayoutTests/fast/canvas/webgl/read-pixels.html:184
 +          return;
Should presumably say:

} else if (!array.length) {
    shouldBe("gl.getError()", "gl.NO_ERROR");
    return;
}
Comment 13 Zhenyao Mo 2010-06-10 17:50:57 PDT
Created attachment 58426 [details]
revised patch: responding to kbr's review
Comment 14 Kenneth Russell 2010-06-10 17:55:24 PDT
Comment on attachment 58426 [details]
revised patch: responding to kbr's review

Looks good.
Comment 15 Dimitri Glazkov (Google) 2010-06-10 21:34:21 PDT
Comment on attachment 58426 [details]
revised patch: responding to kbr's review

Make it so.
Comment 16 WebKit Commit Bot 2010-06-11 08:03:46 PDT
Comment on attachment 58426 [details]
revised patch: responding to kbr's review

Clearing flags on attachment: 58426

Committed r61019: <http://trac.webkit.org/changeset/61019>
Comment 17 WebKit Commit Bot 2010-06-11 08:03:52 PDT
All reviewed patches have been landed.  Closing bug.