<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[279331] releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/279331">279331</a></dd>
<dt>Author</dt> <dd>aperez@igalia.com</dd>
<dt>Date</dt> <dd>2021-06-28 04:52:38 -0700 (Mon, 28 Jun 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/278152">r278152</a> - Cherry-pick ANGLE: D3D11: Skip blits if there is no intersection of dest areas
https://bugs.webkit.org/show_bug.cgi?id=225190
<rdar://77084155>

Patch by Kimmo Kinnunen <kkinnunen@apple.com> on 2021-05-27
Reviewed by David Kilzer.

Cherry-pick ANGLE commit b574643ef28c92fcea5122dd7a72acb42a514eed
Fixes a security issue on D3D11.
Potential a correctness issue on some OpenGL drivers.
No effect on Metal, but the nodiscard part is still useful.

Upstream description:
D3D11: Skip blits if there is no intersection of dest areas

Blit11 would clip the destination rectangle with the destination size
but ignore the result. gl::ClipRectangle returns false when the
rectangles do not intersect at all, indicating the blit can be skipped.

This could lead to an out-of-bounds write to the GPU memory for the
destination texture.

Mark ClipRectangle as nodiscard to prevent future issues.
* src/libANGLE/angletypes.h:
* src/libANGLE/renderer/d3d/d3d11/Blit11.cpp:
* src/libANGLE/renderer/gl/FramebufferGL.cpp:
(rx::FramebufferGL::clipSrcRegion):
* src/libANGLE/renderer/metal/ContextMtl.mm:
(rx::ContextMtl::updateScissor):
* src/libANGLE/renderer/vulkan/ContextVk.cpp:
(rx::ContextVk::updateScissor):
* src/tests/gl_tests/BlitFramebufferANGLETest.cpp:
(TEST_P):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit232SourceThirdPartyANGLEChangeLog">releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit232SourceThirdPartyANGLEsrclibANGLEangletypesh">releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/angletypes.h</a></li>
<li><a href="#releasesWebKitGTKwebkit232SourceThirdPartyANGLEsrclibANGLErendererd3dd3d11Blit11cpp">releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit232SourceThirdPartyANGLEsrclibANGLErendererglFramebufferGLcpp">releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/gl/FramebufferGL.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit232SourceThirdPartyANGLEsrclibANGLErenderermetalContextMtlmm">releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm</a></li>
<li><a href="#releasesWebKitGTKwebkit232SourceThirdPartyANGLEsrclibANGLErenderervulkanContextVkcpp">releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/vulkan/ContextVk.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit232SourceThirdPartyANGLEsrctestsgl_testsBlitFramebufferANGLETestcpp">releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/tests/gl_tests/BlitFramebufferANGLETest.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="releasesWebKitGTKwebkit232SourceThirdPartyANGLEChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/ChangeLog (279330 => 279331)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/ChangeLog 2021-06-28 11:49:48 UTC (rev 279330)
+++ releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/ChangeLog    2021-06-28 11:52:38 UTC (rev 279331)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2021-05-27  Kimmo Kinnunen  <kkinnunen@apple.com>
+
+        Cherry-pick ANGLE: D3D11: Skip blits if there is no intersection of dest areas
+        https://bugs.webkit.org/show_bug.cgi?id=225190
+        <rdar://77084155>
+
+        Reviewed by David Kilzer.
+
+        Cherry-pick ANGLE commit b574643ef28c92fcea5122dd7a72acb42a514eed
+        Fixes a security issue on D3D11.
+        Potential a correctness issue on some OpenGL drivers.
+        No effect on Metal, but the nodiscard part is still useful.
+
+        Upstream description:
+        D3D11: Skip blits if there is no intersection of dest areas
+
+        Blit11 would clip the destination rectangle with the destination size
+        but ignore the result. gl::ClipRectangle returns false when the
+        rectangles do not intersect at all, indicating the blit can be skipped.
+
+        This could lead to an out-of-bounds write to the GPU memory for the
+        destination texture.
+
+        Mark ClipRectangle as nodiscard to prevent future issues.
+        * src/libANGLE/angletypes.h:
+        * src/libANGLE/renderer/d3d/d3d11/Blit11.cpp:
+        * src/libANGLE/renderer/gl/FramebufferGL.cpp:
+        (rx::FramebufferGL::clipSrcRegion):
+        * src/libANGLE/renderer/metal/ContextMtl.mm:
+        (rx::ContextMtl::updateScissor):
+        * src/libANGLE/renderer/vulkan/ContextVk.cpp:
+        (rx::ContextVk::updateScissor):
+        * src/tests/gl_tests/BlitFramebufferANGLETest.cpp:
+        (TEST_P):
+
</ins><span class="cx"> 2021-02-25  Kyle Piddington  <kpiddington@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Fix crashes in fast/canvas/webgl/texImage video tests
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit232SourceThirdPartyANGLEsrclibANGLEangletypesh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/angletypes.h (279330 => 279331)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/angletypes.h 2021-06-28 11:49:48 UTC (rev 279330)
+++ releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/angletypes.h    2021-06-28 11:52:38 UTC (rev 279331)
</span><span class="lines">@@ -84,7 +84,9 @@
</span><span class="cx"> bool operator!=(const Rectangle &a, const Rectangle &b);
</span><span class="cx"> 
</span><span class="cx"> // Calculate the intersection of two rectangles.  Returns false if the intersection is empty.
</span><del>-bool ClipRectangle(const Rectangle &source, const Rectangle &clip, Rectangle *intersection);
</del><ins>+ANGLE_NO_DISCARD bool ClipRectangle(const Rectangle &source,
+                                    const Rectangle &clip,
+                                    Rectangle *intersection);
</ins><span class="cx"> // Calculate the smallest rectangle that covers both rectangles.  This rectangle may cover areas
</span><span class="cx"> // not covered by the two rectangles, for example in this situation:
</span><span class="cx"> //
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit232SourceThirdPartyANGLEsrclibANGLErendererd3dd3d11Blit11cpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp (279330 => 279331)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp        2021-06-28 11:49:48 UTC (rev 279330)
+++ releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp   2021-06-28 11:52:38 UTC (rev 279331)
</span><span class="lines">@@ -141,7 +141,10 @@
</span><span class="cx">                           uint8_t *destData)
</span><span class="cx"> {
</span><span class="cx">     gl::Rectangle clippedDestArea(destArea.x, destArea.y, destArea.width, destArea.height);
</span><del>-    gl::ClipRectangle(clippedDestArea, clipRect, &clippedDestArea);
</del><ins>+    if (!gl::ClipRectangle(clippedDestArea, clipRect, &clippedDestArea))
+    {
+        return;
+    }
</ins><span class="cx"> 
</span><span class="cx">     // Determine if entire rows can be copied at once instead of each individual pixel. There
</span><span class="cx">     // must be no out of bounds lookups, whole rows copies, and no scale.
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit232SourceThirdPartyANGLEsrclibANGLErendererglFramebufferGLcpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/gl/FramebufferGL.cpp (279330 => 279331)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/gl/FramebufferGL.cpp        2021-06-28 11:49:48 UTC (rev 279330)
+++ releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/gl/FramebufferGL.cpp   2021-06-28 11:52:38 UTC (rev 279331)
</span><span class="lines">@@ -1117,7 +1117,10 @@
</span><span class="cx">         // If pixels lying outside the read framebuffer, adjust src region
</span><span class="cx">         // and dst region to appropriate in-bounds regions respectively.
</span><span class="cx">         gl::Rectangle realSourceRegion;
</span><del>-        ClipRectangle(bounds.sourceRegion, bounds.sourceBounds, &realSourceRegion);
</del><ins>+        if (!ClipRectangle(bounds.sourceRegion, bounds.sourceBounds, &realSourceRegion))
+        {
+            return angle::Result::Stop;
+        }
</ins><span class="cx">         GLuint xOffset = realSourceRegion.x - bounds.sourceRegion.x;
</span><span class="cx">         GLuint yOffset = realSourceRegion.y - bounds.sourceRegion.y;
</span><span class="cx"> 
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit232SourceThirdPartyANGLEsrclibANGLErenderermetalContextMtlmm"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm (279330 => 279331)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm 2021-06-28 11:49:48 UTC (rev 279330)
+++ releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm    2021-06-28 11:52:38 UTC (rev 279331)
</span><span class="lines">@@ -1836,7 +1836,10 @@
</span><span class="cx"> 
</span><span class="cx">     // Clip the render area to the viewport.
</span><span class="cx">     gl::Rectangle viewportClippedRenderArea;
</span><del>-    gl::ClipRectangle(renderArea, glState.getViewport(), &viewportClippedRenderArea);
</del><ins>+    if (!gl::ClipRectangle(renderArea, glState.getViewport(), &viewportClippedRenderArea))
+    {
+        viewportClippedRenderArea = gl::Rectangle();
+    }
</ins><span class="cx"> 
</span><span class="cx">     gl::Rectangle scissoredArea = ClipRectToScissor(getState(), viewportClippedRenderArea, false);
</span><span class="cx">     if (framebufferMtl->flipY())
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit232SourceThirdPartyANGLEsrclibANGLErenderervulkanContextVkcpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/vulkan/ContextVk.cpp (279330 => 279331)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/vulkan/ContextVk.cpp        2021-06-28 11:49:48 UTC (rev 279330)
+++ releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/libANGLE/renderer/vulkan/ContextVk.cpp   2021-06-28 11:52:38 UTC (rev 279331)
</span><span class="lines">@@ -2616,8 +2616,11 @@
</span><span class="cx"> 
</span><span class="cx">     // Clip the render area to the viewport.
</span><span class="cx">     gl::Rectangle viewportClippedRenderArea;
</span><del>-    gl::ClipRectangle(renderArea, getCorrectedViewport(glState.getViewport()),
-                      &viewportClippedRenderArea);
</del><ins>+    if (!gl::ClipRectangle(renderArea, getCorrectedViewport(glState.getViewport()),
+                           &viewportClippedRenderArea))
+    {
+        viewportClippedRenderArea = gl::Rectangle();
+    }
</ins><span class="cx"> 
</span><span class="cx">     gl::Rectangle scissoredArea = ClipRectToScissor(getState(), viewportClippedRenderArea, false);
</span><span class="cx">     gl::Rectangle rotatedScissoredArea;
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit232SourceThirdPartyANGLEsrctestsgl_testsBlitFramebufferANGLETestcpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/tests/gl_tests/BlitFramebufferANGLETest.cpp (279330 => 279331)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/tests/gl_tests/BlitFramebufferANGLETest.cpp   2021-06-28 11:49:48 UTC (rev 279330)
+++ releases/WebKitGTK/webkit-2.32/Source/ThirdParty/ANGLE/src/tests/gl_tests/BlitFramebufferANGLETest.cpp      2021-06-28 11:52:38 UTC (rev 279331)
</span><span class="lines">@@ -2437,6 +2437,30 @@
</span><span class="cx">     EXPECT_GL_ERROR(GL_INVALID_VALUE);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+// Test an edge case in D3D11 stencil blitting on the CPU that does not properly clip the
+// destination regions
+TEST_P(BlitFramebufferTest, BlitFramebufferStencilClipNoIntersection)
+{
+    GLFramebuffer framebuffers[2];
+    glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
+    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
+
+    GLRenderbuffer renderbuffers[2];
+    glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
+    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
+    glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
+                              renderbuffers[0]);
+
+    glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
+    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
+    glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
+                              renderbuffers[1]);
+
+    glBlitFramebuffer(0, 0, 4, 4, 1 << 24, 1 << 24, 1 << 25, 1 << 25, GL_STENCIL_BUFFER_BIT,
+                      GL_NEAREST);
+    EXPECT_GL_NO_ERROR();
+}
+
</ins><span class="cx"> // Use this to select which configurations (e.g. which renderer, which GLES major version) these
</span><span class="cx"> // tests should be run against.
</span><span class="cx"> ANGLE_INSTANTIATE_TEST(BlitFramebufferANGLETest,
</span></span></pre>
</div>
</div>

</body>
</html>