Title: [186840] trunk
Revision
186840
Author
[email protected]
Date
2015-07-15 09:02:39 -0700 (Wed, 15 Jul 2015)

Log Message

Negative scroll snap repeat values cause web process to hang indefinitely
https://bugs.webkit.org/show_bug.cgi?id=146953
Source/WebCore:

<rdar://problem/21823681>

Patch by Wenson Hsieh <[email protected]> on 2015-07-15
Reviewed by Simon Fraser.

Fixed dangerous behavior caused by setting -scroll-snap-points-x or -y to negative or very small
positive values. In the case of negative or 0 repeats, the web process would hang indefinitely. In
the case of very small positive values, a massive amount of memory could potentially be allocated
just to store snap offsets.

Tests: css3/scroll-snap/scroll-snap-negative-repeat.html
       css3/scroll-snap/scroll-snap-subpixel-repeat.html

* css/CSSParser.cpp:
(WebCore::CSSParser::parseNonElementSnapPoints): Changed to consider negative snap repeat values as invalid CSS.
* page/scrolling/AxisScrollSnapOffsets.cpp:
(WebCore::updateFromStyle): Changed to threshold non-negative snap repeat values to 1px.

LayoutTests:

Patch by Wenson Hsieh <[email protected]> on 2015-07-15
Reviewed by Simon Fraser.

The first test case checks that setting -scroll-snap-points-x or -y to a negative value
will not cause the web process to hang. The second test case (in a similar vein) checks
that tiny subpixel snap repeats generate a reasonable number of snap offsets.

* css3/scroll-snap/scroll-snap-negative-repeat-expected.txt: Added.
* css3/scroll-snap/scroll-snap-negative-repeat.html: Added.
* css3/scroll-snap/scroll-snap-subpixel-repeat-expected.txt: Added.
* css3/scroll-snap/scroll-snap-subpixel-repeat.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (186839 => 186840)


--- trunk/LayoutTests/ChangeLog	2015-07-15 16:01:32 UTC (rev 186839)
+++ trunk/LayoutTests/ChangeLog	2015-07-15 16:02:39 UTC (rev 186840)
@@ -1,3 +1,19 @@
+2015-07-15  Wenson Hsieh  <[email protected]>
+
+        Negative scroll snap repeat values cause web process to hang indefinitely
+        https://bugs.webkit.org/show_bug.cgi?id=146953
+
+        Reviewed by Simon Fraser.
+
+        The first test case checks that setting -scroll-snap-points-x or -y to a negative value
+        will not cause the web process to hang. The second test case (in a similar vein) checks
+        that tiny subpixel snap repeats generate a reasonable number of snap offsets.
+
+        * css3/scroll-snap/scroll-snap-negative-repeat-expected.txt: Added.
+        * css3/scroll-snap/scroll-snap-negative-repeat.html: Added.
+        * css3/scroll-snap/scroll-snap-subpixel-repeat-expected.txt: Added.
+        * css3/scroll-snap/scroll-snap-subpixel-repeat.html: Added.
+
 2015-07-15  David Kilzer  <[email protected]>
 
         http/tests/misc/large-js-program.php crashes slowly in Debug builds on Windows

Added: trunk/LayoutTests/css3/scroll-snap/scroll-snap-negative-repeat-expected.txt (0 => 186840)


--- trunk/LayoutTests/css3/scroll-snap/scroll-snap-negative-repeat-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/css3/scroll-snap/scroll-snap-negative-repeat-expected.txt	2015-07-15 16:02:39 UTC (rev 186840)
@@ -0,0 +1,9 @@
+Tests that negative repeat() values don't hang on snap point computation.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/css3/scroll-snap/scroll-snap-negative-repeat.html (0 => 186840)


--- trunk/LayoutTests/css3/scroll-snap/scroll-snap-negative-repeat.html	                        (rev 0)
+++ trunk/LayoutTests/css3/scroll-snap/scroll-snap-negative-repeat.html	2015-07-15 16:02:39 UTC (rev 186840)
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <style>
+            body {
+                -webkit-scroll-snap-type: mandatory;
+                -webkit-scroll-snap-points-y: repeat(-400px);
+                height: 5000px;
+            }
+        </style>
+        <script src=""
+    </head>
+    <body>
+        <div id="console"></div>
+        <script>
+        description("Tests that negative repeat() values don't hang on snap point computation.");
+        </script>
+        <script src=""
+    </body>
+</html>
+

Added: trunk/LayoutTests/css3/scroll-snap/scroll-snap-subpixel-repeat-expected.txt (0 => 186840)


--- trunk/LayoutTests/css3/scroll-snap/scroll-snap-subpixel-repeat-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/css3/scroll-snap/scroll-snap-subpixel-repeat-expected.txt	2015-07-15 16:02:39 UTC (rev 186840)
@@ -0,0 +1,13 @@
+Tests that small positive repeat() values generates a reasonable number of snap offsets.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Number of snap offsets: 99
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/css3/scroll-snap/scroll-snap-subpixel-repeat.html (0 => 186840)


--- trunk/LayoutTests/css3/scroll-snap/scroll-snap-subpixel-repeat.html	                        (rev 0)
+++ trunk/LayoutTests/css3/scroll-snap/scroll-snap-subpixel-repeat.html	2015-07-15 16:02:39 UTC (rev 186840)
@@ -0,0 +1,71 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <style>
+            #gallery {
+                height: 100px;
+                width: 100px;
+                overflow-x: hidden;
+                overflow-y: auto;
+                -webkit-scroll-snap-type: mandatory;
+                -webkit-scroll-snap-points-y: repeat(0.0001px);
+                margin: 0;
+                padding: 0;
+            }
+
+            .colorBox {
+                width: 100px;
+                height: 100px;
+            }
+
+            #item0 { background-color: red; }
+            #item1 { background-color: green; }
+        </style>
+        <script src=""
+        <script>
+        function runTest()
+        {
+            var gallery = document.getElementById("gallery");
+
+            if (window.testRunner) {
+                window.jsTestIsAsync = true;
+                testRunner.dumpAsText();
+                testRunner.waitUntilDone();
+                setTimeout(dumpSnapOffsets, 0);
+            }
+
+            function snapOffsetsFromString(offsetsAsString)
+            {
+                var startIndex = offsetsAsString.search(/\{/);
+                var endIndex = offsetsAsString.search(/\}/);
+                if (startIndex == -1 || endIndex == -1 || endIndex <= startIndex)
+                    return []
+
+                return offsetsAsString
+                    .substring(startIndex + 1, endIndex - startIndex - 1)
+                    .trim()
+                    .split(",")
+                    .map(function(s) { return parseFloat(s.trim()) });
+            }
+
+            function dumpSnapOffsets()
+            {
+                var offsets = snapOffsetsFromString(window.internals.scrollSnapOffsets(gallery));
+                debug("Number of snap offsets: " + offsets.length);
+                finishJSTest();
+            }
+        }
+        </script>
+    </head>
+    <body _onload_="runTest()">
+        <div id="gallery">
+            <div id="item0" class="colorBox"></div>
+            <div id="item1" class="colorBox"></div>
+        </div>
+        <div id="console"></div>
+        <script>
+        description("Tests that small positive repeat() values generates a reasonable number of snap offsets.");
+        </script>
+        <script src=""
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (186839 => 186840)


--- trunk/Source/WebCore/ChangeLog	2015-07-15 16:01:32 UTC (rev 186839)
+++ trunk/Source/WebCore/ChangeLog	2015-07-15 16:02:39 UTC (rev 186840)
@@ -1,3 +1,24 @@
+2015-07-15  Wenson Hsieh  <[email protected]>
+
+        Negative scroll snap repeat values cause web process to hang indefinitely
+        https://bugs.webkit.org/show_bug.cgi?id=146953
+        <rdar://problem/21823681>
+
+        Reviewed by Simon Fraser.
+
+        Fixed dangerous behavior caused by setting -scroll-snap-points-x or -y to negative or very small
+        positive values. In the case of negative or 0 repeats, the web process would hang indefinitely. In
+        the case of very small positive values, a massive amount of memory could potentially be allocated
+        just to store snap offsets.
+
+        Tests: css3/scroll-snap/scroll-snap-negative-repeat.html
+               css3/scroll-snap/scroll-snap-subpixel-repeat.html
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseNonElementSnapPoints): Changed to consider negative snap repeat values as invalid CSS.
+        * page/scrolling/AxisScrollSnapOffsets.cpp:
+        (WebCore::updateFromStyle): Changed to threshold non-negative snap repeat values to 1px.
+
 2015-07-14  Dean Jackson  <[email protected]>
 
         Placeholder colors should be system grays

Modified: trunk/Source/WebCore/css/CSSParser.cpp (186839 => 186840)


--- trunk/Source/WebCore/css/CSSParser.cpp	2015-07-15 16:01:32 UTC (rev 186839)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2015-07-15 16:02:39 UTC (rev 186840)
@@ -3397,7 +3397,7 @@
             && value->function->args->size() == 1
             && equalIgnoringCase(value->function->name, "repeat(")) {
             ValueWithCalculation argumentWithCalculation(*value->function->args.get()->current());
-            if (validateUnit(argumentWithCalculation, FLength | FPercent)) {
+            if (validateUnit(argumentWithCalculation, FLength | FPercent | FNonNeg)) {
                 values->append(cssValuePool().createValue(LengthRepeat::create(createPrimitiveNumericValue(argumentWithCalculation))));
                 m_valueList->next();
                 if (m_valueList->current())

Modified: trunk/Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp (186839 => 186840)


--- trunk/Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp	2015-07-15 16:01:32 UTC (rev 186839)
+++ trunk/Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp	2015-07-15 16:02:39 UTC (rev 186840)
@@ -87,7 +87,9 @@
 
     auto* points = (axis == ScrollEventAxis::Horizontal) ? style.scrollSnapPointsX() : style.scrollSnapPointsY();
     bool hasRepeat = points ? points->hasRepeat : false;
-    LayoutUnit repeatOffset = points ? valueForLength(points->repeatOffset, viewSize) : LayoutUnit();
+    LayoutUnit repeatOffset = points ? valueForLength(points->repeatOffset, viewSize) : LayoutUnit::fromPixel(1);
+    repeatOffset = std::max<LayoutUnit>(repeatOffset, LayoutUnit::fromPixel(1));
+    
     LayoutUnit destinationOffset = destinationOffsetForViewSize(axis, style.scrollSnapDestination(), viewSize);
     LayoutUnit curSnapPositionShift = 0;
     LayoutUnit maxScrollOffset = scrollSize - viewSize;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to