Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/WebKit/Source/core/css/CSSSelectorTest.cpp

Issue 2191253002: Prevent integer overflows in ANPlusB handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove longs Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/css/CSSTestHelper.h" 5 #include "core/css/CSSTestHelper.h"
6 #include "core/css/RuleSet.h" 6 #include "core/css/RuleSet.h"
7 7
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace blink { 10 namespace blink {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 ".a.b .c {}"; 48 ".a.b .c {}";
49 49
50 helper.addCSSRules(cssRules); 50 helper.addCSSRules(cssRules);
51 EXPECT_EQ(30u, helper.ruleSet().ruleCount()); // .a, .b counts as two rules. 51 EXPECT_EQ(30u, helper.ruleSet().ruleCount()); // .a, .b counts as two rules.
52 #ifndef NDEBUG 52 #ifndef NDEBUG
53 helper.ruleSet().show(); 53 helper.ruleSet().show();
54 #endif 54 #endif
55 } 55 }
56 56
57 TEST(CSSSelector, OverflowRareDataMatchNth)
58 {
59 int maxInt = std::numeric_limits<int>::max();
60 int minInt = std::numeric_limits<int>::min();
61 CSSSelector selector;
62
63 // Overflow count - b (maxInt - -1 = maxInt + 1)
64 selector.setNth(1, -1);
65 EXPECT_FALSE(selector.matchNth(maxInt));
66 // 0 - (minInt) = maxInt + 1
67 selector.setNth(1, minInt);
68 EXPECT_FALSE(selector.matchNth(0));
69 // minInt - 1
70 selector.setNth(1, 1);
71 EXPECT_FALSE(selector.matchNth(minInt));
72
73 // Overflow b - count (0 - minInt = maxInt + 1)
74 selector.setNth(-1, 0);
75 EXPECT_FALSE(selector.matchNth(minInt));
76 // maxInt - -1 = maxInt + 1
77 selector.setNth(-1, maxInt);
78 EXPECT_FALSE(selector.matchNth(-1));
79 // minInt - 1
80 selector.setNth(-1, minInt);
81 EXPECT_FALSE(selector.matchNth(1));
82
83 // a shouldn't negate to itself (and minInt negates to itself).
84 // Note: This test can only fail when using ubsan.
85 selector.setNth(minInt, 10);
86 EXPECT_FALSE(selector.matchNth(2));
87 }
88
57 } // namespace blink 89 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698