⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 187189 in webkit


Ignore:
Timestamp:
Jul 22, 2015, 2:55:48 PM (11 years ago)
Author:
dino@apple.com
Message:

Out of bounds in WebGLRenderingContext::simulateVertexAttrib0
https://bugs.webkit.org/show_bug.cgi?id=147176
<rdar://problem/21567767>

Reviewed by Oliver Hunt.

Source/WebCore:

Test: fast/canvas/webgl/out-of-bounds-simulated-vertexAttrib0-drawArrays.html

Add overflow checking for the drawing calls, specifically the way
they may simulate vertexAttrib0.

  • html/canvas/WebGLRenderingContextBase.cpp:

(WebCore::WebGLRenderingContextBase::validateDrawArrays): Call new validation method.
(WebCore::WebGLRenderingContextBase::validateDrawElements): Ditto.
(WebCore::WebGLRenderingContextBase::validateSimulatedVertexAttrib0): New method that
validates the parameters used to create the simulated attribute.
(WebCore::WebGLRenderingContextBase::simulateVertexAttrib0): No need to do overflow
checking here now that the validation method does it for us.
(WebCore::WebGLRenderingContextBase::validateVertexAttributes): Deleted.

  • html/canvas/WebGLRenderingContextBase.h: Add new validation method.

LayoutTests:

  • fast/canvas/webgl/out-of-bounds-simulated-vertexAttrib0-drawArrays-expected.txt: Added.
  • fast/canvas/webgl/out-of-bounds-simulated-vertexAttrib0-drawArrays.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r187185 r187189  
     12015-07-22  Dean Jackson  <dino@apple.com>
     2
     3        Out of bounds in WebGLRenderingContext::simulateVertexAttrib0
     4        https://bugs.webkit.org/show_bug.cgi?id=147176
     5        <rdar://problem/21567767>
     6
     7        Reviewed by Oliver Hunt.
     8
     9        * fast/canvas/webgl/out-of-bounds-simulated-vertexAttrib0-drawArrays-expected.txt: Added.
     10        * fast/canvas/webgl/out-of-bounds-simulated-vertexAttrib0-drawArrays.html: Added.
     11
    1122015-07-22  Joseph Pecoraro  <pecoraro@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r187185 r187189  
     12015-07-22  Dean Jackson  <dino@apple.com>
     2
     3        Out of bounds in WebGLRenderingContext::simulateVertexAttrib0
     4        https://bugs.webkit.org/show_bug.cgi?id=147176
     5        <rdar://problem/21567767>
     6
     7        Reviewed by Oliver Hunt.
     8
     9        Test: fast/canvas/webgl/out-of-bounds-simulated-vertexAttrib0-drawArrays.html
     10
     11        Add overflow checking for the drawing calls, specifically the way
     12        they may simulate vertexAttrib0.
     13
     14        * html/canvas/WebGLRenderingContextBase.cpp:
     15        (WebCore::WebGLRenderingContextBase::validateDrawArrays): Call new validation method.
     16        (WebCore::WebGLRenderingContextBase::validateDrawElements): Ditto.
     17        (WebCore::WebGLRenderingContextBase::validateSimulatedVertexAttrib0): New method that
     18        validates the parameters used to create the simulated attribute.
     19        (WebCore::WebGLRenderingContextBase::simulateVertexAttrib0): No need to do overflow
     20        checking here now that the validation method does it for us.
     21        (WebCore::WebGLRenderingContextBase::validateVertexAttributes): Deleted.
     22        * html/canvas/WebGLRenderingContextBase.h: Add new validation method.
     23
    1242015-07-22  Joseph Pecoraro  <pecoraro@apple.com>
    225
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp

    r186384 r187189  
    17091709        return true;
    17101710
    1711 
    17121711    // Look in each consumed vertex attrib (by the current program).
    17131712    bool sawNonInstancedAttrib = false;
     
    17941793            return false;
    17951794        }
     1795        if (!validateSimulatedVertexAttrib0(checkedSum.unsafeGet() - 1)) {
     1796            synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "attempt to access outside the bounds of the simulated vertexAttrib0 array");
     1797            return false;
     1798        }
    17961799    } else {
    17971800        if (!validateVertexAttributes(0)) {
     
    18741877            }
    18751878        }
     1879
     1880        if (!validateSimulatedVertexAttrib0(numElements)) {
     1881            synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "attempt to access outside the bounds of the simulated vertexAttrib0 array");
     1882            return false;
     1883        }
     1884
    18761885    } else {
    18771886        if (!validateVertexAttributes(0)) {
     
    46704679}
    46714680
     4681bool WebGLRenderingContextBase::validateSimulatedVertexAttrib0(GC3Dsizei numVertex)
     4682{
     4683    if (numVertex < 0)
     4684        return false;
     4685
     4686    if (!m_currentProgram)
     4687        return true;
     4688
     4689    bool usingVertexAttrib0 = m_currentProgram->isUsingVertexAttrib0();
     4690    if (!usingVertexAttrib0)
     4691        return true;
     4692
     4693    auto& state = m_boundVertexArrayObject->getVertexAttribState(0);
     4694    if (state.enabled)
     4695        return true;
     4696
     4697    Checked<GC3Dsizei, RecordOverflow> bufferSize(numVertex);
     4698    bufferSize += 1;
     4699    bufferSize *= Checked<GC3Dsizei>(4);
     4700    Checked<GC3Dsizeiptr, RecordOverflow> bufferDataSize(bufferSize);
     4701    bufferDataSize *= Checked<GC3Dsizeiptr>(sizeof(GC3Dfloat));
     4702    return !bufferDataSize.hasOverflowed();
     4703}
     4704
    46724705bool WebGLRenderingContextBase::simulateVertexAttrib0(GC3Dsizei numVertex)
    46734706{
    4674     const WebGLVertexArrayObjectBase::VertexAttribState& state = m_boundVertexArrayObject->getVertexAttribState(0);
    4675     const VertexAttribValue& attribValue = m_vertexAttribValue[0];
    46764707    if (!m_currentProgram)
    46774708        return false;
     
    46794710    if (usingVertexAttrib0)
    46804711        m_vertexAttrib0UsedBefore = true;
     4712
     4713    auto& state = m_boundVertexArrayObject->getVertexAttribState(0);
    46814714    if (state.enabled && usingVertexAttrib0)
    46824715        return false;
     
    46854718    m_vertexAttrib0UsedBefore = true;
    46864719    m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_vertexAttrib0Buffer->object());
    4687     Checked<GC3Dsizeiptr, RecordOverflow> bufferDataSize(numVertex);
    4688     bufferDataSize += 1;
    4689     bufferDataSize *= Checked<GC3Dsizeiptr, RecordOverflow>(4 * sizeof(GC3Dfloat));
    4690     if (bufferDataSize.hasOverflowed())
    4691         return false;
     4720
     4721    Checked<GC3Dsizei> bufferSize(numVertex);
     4722    bufferSize += 1;
     4723    bufferSize *= Checked<GC3Dsizei>(4);
     4724
     4725    Checked<GC3Dsizeiptr> bufferDataSize(bufferSize);
     4726    bufferDataSize *= Checked<GC3Dsizeiptr>(sizeof(GC3Dfloat));
     4727
    46924728    if (bufferDataSize.unsafeGet() > m_vertexAttrib0BufferSize) {
    46934729        m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, bufferDataSize.unsafeGet(), 0, GraphicsContext3D::DYNAMIC_DRAW);
     
    46954731        m_forceAttrib0BufferRefill = true;
    46964732    }
     4733
     4734    auto& attribValue = m_vertexAttribValue[0];
     4735
    46974736    if (usingVertexAttrib0
    46984737        && (m_forceAttrib0BufferRefill
     
    47014740            || attribValue.value[2] != m_vertexAttrib0BufferValue[2]
    47024741            || attribValue.value[3] != m_vertexAttrib0BufferValue[3])) {
    4703         auto bufferData = std::make_unique<GC3Dfloat[]>((numVertex + 1) * 4);
     4742
     4743        auto bufferData = std::make_unique<GC3Dfloat[]>(bufferSize.unsafeGet());
    47044744        for (GC3Dsizei ii = 0; ii < numVertex + 1; ++ii) {
    47054745            bufferData[ii * 4] = attribValue.value[0];
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h

    r182544 r187189  
    791791    bool checkObjectToBeBound(const char* functionName, WebGLObject*, bool& deleted);
    792792
    793     // Helpers for simulating vertexAttrib0
     793    // Helpers for simulating vertexAttrib0.
    794794    void initVertexAttrib0();
    795795    bool simulateVertexAttrib0(GC3Dsizei numVertex);
     796    bool validateSimulatedVertexAttrib0(GC3Dsizei numVertex);
    796797    void restoreStatesAfterVertexAttrib0Simulation();
    797798
Note: See TracChangeset for help on using the changeset viewer.