Changeset 147042 in webkit


Ignore:
Timestamp:
Mar 27, 2013 6:35:02 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Refactor validation checks for texture uploads
https://bugs.webkit.org/show_bug.cgi?id=111012

Patch by Jun Jiang <jun.a.jiang@intel.com> on 2013-03-27
Reviewed by Kenneth Russell.

Move the validation checks to the entry level of tex{Sub}Image2D, return early for invalid parameters and avoid duplicated checks.
Moreover, turn all the validation checks at the bottom level - tex{Sub}Image2DBase into assertions.

Already covered by current tests.

  • html/canvas/WebGLRenderingContext.cpp:

(WebCore::WebGLRenderingContext::copyTexSubImage2D):
(WebCore::WebGLRenderingContext::texImage2DBase):
(WebCore::WebGLRenderingContext::texImage2DImpl):
(WebCore::WebGLRenderingContext::validateTexFunc): A helper function for tex{Sub}Image2D to check input parameters.
(WebCore::WebGLRenderingContext::texImage2D):
(WebCore::WebGLRenderingContext::texSubImage2DBase):
(WebCore::WebGLRenderingContext::texSubImage2DImpl):
(WebCore::WebGLRenderingContext::texSubImage2D):
(WebCore::WebGLRenderingContext::validateHTMLImageElement):
(WebCore::WebGLRenderingContext::validateHTMLCanvasElement):
(WebCore::WebGLRenderingContext::validateHTMLVideoElement):

  • html/canvas/WebGLRenderingContext.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r147041 r147042  
     12013-03-27  Jun Jiang  <jun.a.jiang@intel.com>
     2
     3        Refactor validation checks for texture uploads
     4        https://bugs.webkit.org/show_bug.cgi?id=111012
     5
     6        Reviewed by Kenneth Russell.
     7
     8        Move the validation checks to the entry level of tex{Sub}Image2D, return early for invalid parameters and avoid duplicated checks.
     9        Moreover, turn all the validation checks at the bottom level - tex{Sub}Image2DBase into assertions.
     10
     11        Already covered by current tests.
     12
     13        * html/canvas/WebGLRenderingContext.cpp:
     14        (WebCore::WebGLRenderingContext::copyTexSubImage2D):
     15        (WebCore::WebGLRenderingContext::texImage2DBase):
     16        (WebCore::WebGLRenderingContext::texImage2DImpl):
     17        (WebCore::WebGLRenderingContext::validateTexFunc): A helper function for tex{Sub}Image2D to check input parameters.
     18        (WebCore::WebGLRenderingContext::texImage2D):
     19        (WebCore::WebGLRenderingContext::texSubImage2DBase):
     20        (WebCore::WebGLRenderingContext::texSubImage2DImpl):
     21        (WebCore::WebGLRenderingContext::texSubImage2D):
     22        (WebCore::WebGLRenderingContext::validateHTMLImageElement):
     23        (WebCore::WebGLRenderingContext::validateHTMLCanvasElement):
     24        (WebCore::WebGLRenderingContext::validateHTMLVideoElement):
     25        * html/canvas/WebGLRenderingContext.h:
     26
    1272013-03-27  Arnaud Renevier  <a.renevier@sisa.samsung.com>
    228
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp

    r146820 r147042  
    14641464    if (!validateSize("copyTexSubImage2D", xoffset, yoffset) || !validateSize("copyTexSubImage2D", width, height))
    14651465        return;
     1466    // Before checking if it is in the range, check if overflow happens first.
     1467    if (xoffset + width < 0 || yoffset + height < 0) {
     1468        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "copyTexSubImage2D", "bad dimensions");
     1469        return;
     1470    }
    14661471    if (xoffset + width > tex->getWidth(target, level) || yoffset + height > tex->getHeight(target, level)) {
    14671472        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "copyTexSubImage2D", "rectangle out of range");
     
    36823687    // FIXME: For now we ignore any errors returned
    36833688    ec = 0;
    3684     if (!validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, level, internalformat, width, height, border, format, type))
    3685         return;
    36863689    WebGLTexture* tex = validateTextureBinding("texImage2D", target, true);
    3687     if (!tex)
    3688         return;
    3689     if (!isGLES2NPOTStrict()) {
    3690         if (level && WebGLTexture::isNPOT(width, height)) {
    3691             synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "level > 0 not power of 2");
    3692             return;
    3693         }
    3694     }
     3690    ASSERT(validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, level, internalformat, width, height, border, format, type));
     3691    ASSERT(tex);
     3692    ASSERT(!level || !WebGLTexture::isNPOT(width, height));
    36953693    if (!pixels) {
    36963694        // Note: Chromium's OpenGL implementation clears textures and isResourceSafe() is therefore true.
     
    37073705        }
    37083706    } else {
    3709         if (!validateSettableTexFormat("texImage2D", internalformat))
    3710             return;
     3707        ASSERT(validateSettableTexFormat("texImage2D", internalformat));
    37113708        m_context->texImage2D(target, level, internalformat, width, height,
    37123709                              border, format, type, pixels);
     
    37193716{
    37203717    ec = 0;
    3721     if (!validateSettableTexFormat("texImage2D", internalformat))
    3722         return;
    37233718    Vector<uint8_t> data;
    37243719    GraphicsContext3D::ImageExtractor imageExtractor(image, domSource, premultiplyAlpha, m_unpackColorspaceConversion == GraphicsContext3D::NONE);
     
    37483743}
    37493744
     3745bool WebGLRenderingContext::validateTexFunc(const char* functionName, TexFuncValidationFunctionType functionType, TexFuncValidationSourceType sourceType, GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint xoffset, GC3Dint yoffset)
     3746{
     3747    // FIXME: Uploading {ImageData, HTMLImageElement, HTMLCanvasElement, HTMLVideoElement} to half floating point texture is not supported yet.
     3748    // See https://bugs.webkit.org/show_bug.cgi?id=110936.
     3749    if (sourceType != SourceArrayBufferView && type == GraphicsContext3D::HALF_FLOAT_OES) {
     3750        synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "Operation not supported yet");
     3751        return false;
     3752    }
     3753
     3754    if (!validateTexFuncParameters(functionName, functionType, target, level, internalformat, width, height, border, format, type))
     3755        return false;
     3756
     3757    WebGLTexture* texture = validateTextureBinding(functionName, target, true);
     3758    if (!texture)
     3759        return false;
     3760
     3761    if (functionType == NotTexSubImage2D) {
     3762        if (level && WebGLTexture::isNPOT(width, height)) {
     3763            synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "level > 0 not power of 2");
     3764            return false;
     3765        }
     3766        // For SourceArrayBufferView, function validateTexFuncData() would handle whether to validate the SettableTexFormat
     3767        // by checking if the ArrayBufferView is null or not.
     3768        if (sourceType != SourceArrayBufferView) {
     3769            if (!validateSettableTexFormat(functionName, format))
     3770                return false;
     3771        }
     3772    } else {
     3773        if (!validateSettableTexFormat(functionName, format))
     3774            return false;
     3775        if (!validateSize(functionName, xoffset, yoffset))
     3776            return false;
     3777        // Before checking if it is in the range, check if overflow happens first.
     3778        if (xoffset + width < 0 || yoffset + height < 0) {
     3779            synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "bad dimensions");
     3780            return false;
     3781        }
     3782        if (xoffset + width > texture->getWidth(target, level) || yoffset + height > texture->getHeight(target, level)) {
     3783            synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "dimensions out of range");
     3784            return false;
     3785        }
     3786        if (texture->getInternalFormat(target, level) != format || texture->getType(target, level) != type) {
     3787            synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "type and format do not match texture");
     3788            return false;
     3789        }
     3790    }
     3791
     3792    return true;
     3793}
     3794
    37503795void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat,
    37513796                                       GC3Dsizei width, GC3Dsizei height, GC3Dint border,
    37523797                                       GC3Denum format, GC3Denum type, ArrayBufferView* pixels, ExceptionCode& ec)
    37533798{
    3754     if (isContextLost() || !validateTexFuncData("texImage2D", level, width, height, format, type, pixels, NullAllowed))
     3799    if (isContextLost() || !validateTexFuncData("texImage2D", level, width, height, format, type, pixels, NullAllowed)
     3800        || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceArrayBufferView, target, level, internalformat, width, height, border, format, type, 0, 0))
    37553801        return;
    37563802    void* data = pixels ? pixels->baseAddress() : 0;
     
    37793825{
    37803826    ec = 0;
    3781     if (isContextLost())
     3827    if (isContextLost() || !pixels || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceImageData, target, level, internalformat, pixels->width(), pixels->height(), 0, format, type, 0, 0))
    37823828        return;
    37833829    Vector<uint8_t> data;
    3784     if (!pixels)
    3785         return;
    3786     if (!validateTexFuncFormatAndType("texImage2D", format, type, level))
    3787         return;
    3788     if (!validateSettableTexFormat("texImage2D", format))
    3789         return;
    3790     // FIXME: Uploading ImageData to half floating point texture is not supported yet
    3791     // https://bugs.webkit.org/show_bug.cgi?id=110936
    3792     if (type == GraphicsContext3D::HALF_FLOAT_OES) {
    3793         synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "texImage2D", "Operation not supported yet");
    3794         return;
    3795     }
    3796 
    37973830    bool needConversion = true;
    37983831    // The data from ImageData is always of format RGBA8.
     
    38173850{
    38183851    ec = 0;
    3819     if (isContextLost())
    3820         return;
    3821     if (!validateHTMLImageElement("texImage2D", image))
    3822         return;
    3823     if (wouldTaintOrigin(image)) {
    3824         ec = SECURITY_ERR;
    3825         return;
    3826     }
    3827     // FIXME: Uploading ImageElement to half floating point texture is not supported yet
    3828     // https://bugs.webkit.org/show_bug.cgi?id=110936
    3829     if (type == GraphicsContext3D::HALF_FLOAT_OES) {
    3830         synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "texImage2D", "Operation not supported yet");
    3831         return;
    3832     }
    3833 
    3834     texImage2DImpl(target, level, internalformat, format, type, image->cachedImage()->imageForRenderer(image->renderer()), GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, ec);
     3852    if (isContextLost() || !validateHTMLImageElement("texImage2D", image, ec))
     3853        return;
     3854    Image* imageForRender = image->cachedImage()->imageForRenderer(image->renderer());
     3855    if (!imageForRender || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLImageElement, target, level, internalformat, imageForRender->width(), imageForRender->height(), 0, format, type, 0, 0))
     3856        return;
     3857
     3858    texImage2DImpl(target, level, internalformat, format, type, imageForRender, GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, ec);
    38353859}
    38363860
     
    38393863{
    38403864    ec = 0;
    3841     if (isContextLost())
    3842         return;
    3843     if (!canvas || !canvas->buffer()) {
    3844         synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "no canvas");
    3845         return;
    3846     }
    3847     if (wouldTaintOrigin(canvas)) {
    3848         ec = SECURITY_ERR;
    3849         return;
    3850     }
    3851     if (!validateTexFuncFormatAndType("texImage2D", format, type, level))
    3852         return;
    3853     if (!validateSettableTexFormat("texImage2D", format))
    3854         return;
    3855     // FIXME: Uploading HTMLCanvasElement to half floating point texture is not supported yet
    3856     // https://bugs.webkit.org/show_bug.cgi?id=110936
    3857     if (type == GraphicsContext3D::HALF_FLOAT_OES) {
    3858         synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "texImage2D", "Operation not supported yet");
    3859         return;
    3860     }
     3865    if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, ec) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvasElement, target, level, internalformat, canvas->width(), canvas->height(), 0, format, type, 0, 0))
     3866        return;
    38613867
    38623868    WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
     
    39023908{
    39033909    ec = 0;
    3904     if (isContextLost())
    3905         return;
    3906     if (!video || !video->videoWidth() || !video->videoHeight()) {
    3907         synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "no video");
    3908         return;
    3909     }
    3910     if (wouldTaintOrigin(video)) {
    3911         ec = SECURITY_ERR;
    3912         return;
    3913     }
    3914     if (!validateTexFuncFormatAndType("texImage2D", format, type, level))
    3915         return;
    3916     if (!validateSettableTexFormat("texImage2D", format))
     3910    if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, ec)
     3911        || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoElement, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0))
    39173912        return;
    39183913
     
    39383933    if (!image)
    39393934        return;
    3940     // FIXME: Uploading HTMLVideoElement to half floating point texture is not supported yet
    3941     // https://bugs.webkit.org/show_bug.cgi?id=110936
    3942     if (type == GraphicsContext3D::HALF_FLOAT_OES) {
    3943         synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "texImage2D", "Operation not supported yet");
    3944         return;
    3945     }
    3946 
    39473935    texImage2DImpl(target, level, internalformat, format, type, image.get(), GraphicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, ec);
    39483936}
     
    40023990    // FIXME: For now we ignore any errors returned
    40033991    ec = 0;
    4004     if (isContextLost())
    4005         return;
    4006     if (!validateTexFuncParameters("texSubImage2D", TexSubImage2D, target, level, format, width, height, 0, format, type))
    4007         return;
    4008     if (!validateSize("texSubImage2D", xoffset, yoffset))
    4009         return;
    4010     if (!validateSettableTexFormat("texSubImage2D", format))
    4011         return;
     3992    ASSERT(!isContextLost());
     3993    ASSERT(validateTexFuncParameters("texSubImage2D", TexSubImage2D, target, level, format, width, height, 0, format, type));
     3994    ASSERT(validateSize("texSubImage2D", xoffset, yoffset));
     3995    ASSERT(validateSettableTexFormat("texSubImage2D", format));
    40123996    WebGLTexture* tex = validateTextureBinding("texSubImage2D", target, true);
    4013     if (!tex)
    4014         return;
    4015     if (xoffset + width > tex->getWidth(target, level) || yoffset + height > tex->getHeight(target, level)) {
    4016         synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "dimensions out of range");
    4017         return;
    4018     }
    4019     if (tex->getInternalFormat(target, level) != format || tex->getType(target, level) != type) {
    4020         synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "texSubImage2D", "type and format do not match texture");
    4021         return;
    4022     }
     3997    if (!tex) {
     3998        ASSERT_NOT_REACHED();
     3999        return;
     4000    }
     4001    ASSERT((xoffset + width) >= 0);
     4002    ASSERT((yoffset + height) >= 0);
     4003    ASSERT(tex->getWidth(target, level) >= (xoffset + width));
     4004    ASSERT(tex->getHeight(target, level) >= (yoffset + height));
     4005    ASSERT(tex->getInternalFormat(target, level) == format);
     4006    ASSERT(tex->getType(target, level) == type);
    40234007    m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
    40244008    cleanupAfterGraphicsCall(false);
     
    40284012{
    40294013    ec = 0;
    4030     if (isContextLost())
    4031         return;
    4032     if (!validateTexFuncFormatAndType("texSubImage2D", format, type, level))
    4033         return;
    4034     if (!validateSettableTexFormat("texSubImage2D", format))
    4035         return;
    40364014    Vector<uint8_t> data;
    40374015    GraphicsContext3D::ImageExtractor imageExtractor(image, domSource, premultiplyAlpha, m_unpackColorspaceConversion == GraphicsContext3D::NONE); 
     
    40654043                                          GC3Denum format, GC3Denum type, ArrayBufferView* pixels, ExceptionCode& ec)
    40664044{
    4067     if (isContextLost() || !validateTexFuncData("texSubImage2D", level, width, height, format, type, pixels, NullNotAllowed))
     4045    if (isContextLost() || !validateTexFuncData("texSubImage2D", level, width, height, format, type, pixels, NullNotAllowed)
     4046        || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceArrayBufferView, target, level, format, width, height, 0, format, type, xoffset, yoffset))
    40684047        return;
    40694048    void* data = pixels->baseAddress();
     
    40914070{
    40924071    ec = 0;
    4093     if (isContextLost())
    4094         return;
    4095     if (!pixels)
    4096         return;
    4097     if (!validateTexFuncFormatAndType("texSubImage2D", format, type, level))
    4098         return;
    4099     if (!validateSettableTexFormat("texSubImage2D", format))
    4100         return;
    4101     // FIXME: Uploading ImageData to half floating point texture is not supported yet
    4102     // https://bugs.webkit.org/show_bug.cgi?id=110936
    4103     if (type == GraphicsContext3D::HALF_FLOAT_OES) {
    4104         synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "texSubImage2D", "Operation not supported yet");
    4105         return;
    4106     }
     4072    if (isContextLost() || !pixels || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceImageData, target, level, format,  pixels->width(), pixels->height(), 0, format, type, xoffset, yoffset))
     4073        return;
    41074074
    41084075    Vector<uint8_t> data;
     
    41294096{
    41304097    ec = 0;
    4131     if (isContextLost())
    4132         return;
    4133     if (!validateHTMLImageElement("texSubImage2D", image))
    4134         return;
    4135     if (wouldTaintOrigin(image)) {
    4136         ec = SECURITY_ERR;
    4137         return;
    4138     }
    4139     // FIXME: Uploading HTMLImageElement to half floating point texture is not supported yet
    4140     // https://bugs.webkit.org/show_bug.cgi?id=110936
    4141     if (type == GraphicsContext3D::HALF_FLOAT_OES) {
    4142         synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "texSubImage2D", "Operation not supported yet");
    4143         return;
    4144     }
    4145 
    4146     texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image->cachedImage()->imageForRenderer(image->renderer()), GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, ec);
     4098    if (isContextLost() || !validateHTMLImageElement("texSubImage2D", image, ec))
     4099        return;
     4100    Image* imageForRender = image->cachedImage()->imageForRenderer(image->renderer());
     4101    if (!imageForRender || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLImageElement, target, level, format, imageForRender->width(), imageForRender->height(), 0, format, type, xoffset, yoffset))
     4102        return;
     4103
     4104    texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRender, GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, ec);
    41474105}
    41484106
     
    41514109{
    41524110    ec = 0;
    4153     if (isContextLost())
    4154         return;
    4155     if (!canvas || !canvas->buffer()) {
    4156         synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "no canvas");
    4157         return;
    4158     }
    4159     if (wouldTaintOrigin(canvas)) {
    4160         ec = SECURITY_ERR;
    4161         return;
    4162     }
    4163     if (!validateTexFuncFormatAndType("texSubImage2D", format, type, level))
    4164         return;
    4165     if (!validateSettableTexFormat("texSubImage2D", format))
    4166         return;
    4167     // FIXME: Uploading HTMLCanvasElement to half floating point texture is not supported yet
    4168     // https://bugs.webkit.org/show_bug.cgi?id=110936
    4169     if (type == GraphicsContext3D::HALF_FLOAT_OES) {
    4170         synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "texSubImage2D", "Operation not supported yet");
    4171         return;
    4172     }
     4111    if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, ec)
     4112        || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElement, target, level, format, canvas->width(), canvas->height(), 0, format, type, xoffset, yoffset))
     4113        return;
    41734114
    41744115    RefPtr<ImageData> imageData = canvas->getImageData();
     
    41844125{
    41854126    ec = 0;
    4186     if (isContextLost())
    4187         return;
    4188     if (!video || !video->videoWidth() || !video->videoHeight()) {
    4189         synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "no video");
    4190         return;
    4191     }
    4192 
    4193     if (wouldTaintOrigin(video)) {
    4194         ec = SECURITY_ERR;
    4195         return;
    4196     }
    4197     if (!validateTexFuncFormatAndType("texSubImage2D", format, type, level))
    4198         return;
    4199     if (!validateSettableTexFormat("texSubImage2D", format))
     4127    if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, ec)
     4128        || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoElement, target, level, format, video->videoWidth(), video->videoHeight(), 0, format, type, xoffset, yoffset))
    42004129        return;
    42014130
     
    42034132    if (!image)
    42044133        return;
    4205     // FIXME: Uploading HTMLVideoElement to half floating point texture is not supported yet
    4206     // https://bugs.webkit.org/show_bug.cgi?id=110936
    4207     if (type == GraphicsContext3D::HALF_FLOAT_OES) {
    4208         synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "texSubImage2D", "Operation not supported yet");
    4209         return;
    4210     }
    4211 
    42124134    texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get(), GraphicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, ec);
    42134135}
     
    56865608}
    56875609
    5688 bool WebGLRenderingContext::validateHTMLImageElement(const char* functionName, HTMLImageElement* image)
     5610bool WebGLRenderingContext::validateHTMLImageElement(const char* functionName, HTMLImageElement* image, ExceptionCode& ec)
    56895611{
    56905612    if (!image || !image->cachedImage()) {
     
    56975619        return false;
    56985620    }
     5621    if (wouldTaintOrigin(image)) {
     5622        ec = SECURITY_ERR;
     5623        return false;
     5624    }
    56995625    return true;
    57005626}
     5627
     5628bool WebGLRenderingContext::validateHTMLCanvasElement(const char* functionName, HTMLCanvasElement* canvas, ExceptionCode& ec)
     5629{
     5630    if (!canvas || !canvas->buffer()) {
     5631        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no canvas");
     5632        return false;
     5633    }
     5634    if (wouldTaintOrigin(canvas)) {
     5635        ec = SECURITY_ERR;
     5636        return false;
     5637    }
     5638    return true;
     5639}
     5640
     5641#if ENABLE(VIDEO)
     5642bool WebGLRenderingContext::validateHTMLVideoElement(const char* functionName, HTMLVideoElement* video, ExceptionCode& ec)
     5643{
     5644    if (!video || !video->videoWidth() || !video->videoHeight()) {
     5645        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no video");
     5646        return false;
     5647    }
     5648    if (wouldTaintOrigin(video)) {
     5649        ec = SECURITY_ERR;
     5650        return false;
     5651    }
     5652    return true;
     5653}
     5654#endif
    57015655
    57025656void WebGLRenderingContext::vertexAttribfImpl(const char* functionName, GC3Duint index, GC3Dsizei expectedSize, GC3Dfloat v0, GC3Dfloat v1, GC3Dfloat v2, GC3Dfloat v3)
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h

    r146820 r147042  
    608608    };
    609609
     610    enum TexFuncValidationSourceType {
     611        SourceArrayBufferView,
     612        SourceImageData,
     613        SourceHTMLImageElement,
     614        SourceHTMLCanvasElement,
     615        SourceHTMLVideoElement,
     616    };
     617
     618    // Helper function for tex{Sub}Image2D to check if the input format/type/level/target/width/height/border/xoffset/yoffset are valid.
     619    // Otherwise, it would return quickly without doing other work.
     620    bool validateTexFunc(const char* functionName, TexFuncValidationFunctionType, TexFuncValidationSourceType, GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width,
     621        GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint xoffset, GC3Dint yoffset);
     622
    610623    // Helper function to check input parameters for functions {copy}Tex{Sub}Image.
    611624    // Generates GL error and returns false if parameters are invalid.
     
    699712    WebGLBuffer* validateBufferDataParameters(const char* functionName, GC3Denum target, GC3Denum usage);
    700713
    701     // Helper function for tex{Sub}Image2D to make sure image is ready.
    702     bool validateHTMLImageElement(const char* functionName, HTMLImageElement*);
     714    // Helper function for tex{Sub}Image2D to make sure image is ready and wouldn't taint Origin.
     715    bool validateHTMLImageElement(const char* functionName, HTMLImageElement*, ExceptionCode&);
     716
     717    // Helper function for tex{Sub}Image2D to make sure canvas is ready and wouldn't taint Origin.
     718    bool validateHTMLCanvasElement(const char* functionName, HTMLCanvasElement*, ExceptionCode&);
     719
     720#if ENABLE(VIDEO)
     721    // Helper function for tex{Sub}Image2D to make sure video is ready wouldn't taint Origin.
     722    bool validateHTMLVideoElement(const char* functionName, HTMLVideoElement*, ExceptionCode&);
     723#endif
    703724
    704725    // Helper functions for vertexAttribNf{v}.
Note: See TracChangeset for help on using the changeset viewer.