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

Unified Diff: third_party/WebKit/Source/core/css/CSSSelectorTest.cpp

Issue 2825993002: Prevent integer overflows in ANPlusB handling (Closed)
Patch Set: Remove incorrect test - testing input as -1 for unsigned doesn't make sense Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/css/CSSSelectorTest.cpp
diff --git a/third_party/WebKit/Source/core/css/CSSSelectorTest.cpp b/third_party/WebKit/Source/core/css/CSSSelectorTest.cpp
index d7cc716f49d12e7e89a5813c3344f6ee4dc8511b..c3268c853aef0852cce432272ae42554515804ab 100644
--- a/third_party/WebKit/Source/core/css/CSSSelectorTest.cpp
+++ b/third_party/WebKit/Source/core/css/CSSSelectorTest.cpp
@@ -54,4 +54,26 @@ TEST(CSSSelector, Representations) {
#endif
}
+TEST(CSSSelector, OverflowRareDataMatchNth) {
+ int max_int = std::numeric_limits<int>::max();
+ int min_int = std::numeric_limits<int>::min();
+ CSSSelector selector;
+
+ // Overflow count - b (max_int - -1 = max_int + 1)
+ selector.SetNth(1, -1);
+ EXPECT_FALSE(selector.MatchNth(max_int));
+ // 0 - (min_int) = max_int + 1
+ selector.SetNth(1, min_int);
+ EXPECT_FALSE(selector.MatchNth(0));
+
+ // min_int - 1
+ selector.SetNth(-1, min_int);
+ EXPECT_FALSE(selector.MatchNth(1));
+
+ // a shouldn't negate to itself (and min_int negates to itself).
+ // Note: This test can only fail when using ubsan.
+ selector.SetNth(min_int, 10);
+ EXPECT_FALSE(selector.MatchNth(2));
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSSelector.cpp ('k') | third_party/WebKit/Source/core/css/parser/CSSSelectorParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698