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

Unified Diff: third_party/WebKit/Source/core/css/CSSSelector.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/CSSSelectorTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/css/CSSSelector.cpp
diff --git a/third_party/WebKit/Source/core/css/CSSSelector.cpp b/third_party/WebKit/Source/core/css/CSSSelector.cpp
index 3a40cb6d6e723789f75dbb111b07a776a24d645e..10fc2bc3cd1182ff986c72acda5fca7c37819628 100644
--- a/third_party/WebKit/Source/core/css/CSSSelector.cpp
+++ b/third_party/WebKit/Source/core/css/CSSSelector.cpp
@@ -933,10 +933,22 @@ bool CSSSelector::RareData::matchNth(int count)
if (nthAValue() > 0) {
if (count < nthBValue())
return false;
+ // Avoid overflow and underflow.
+ if (UNLIKELY((nthBValue() > 0 && count < std::numeric_limits<int>::min() + nthBValue())
+ || (nthBValue() < 0 && count > std::numeric_limits<int>::max() + nthBValue())))
+ return false;
return (count - nthBValue()) % nthAValue() == 0;
}
if (count > nthBValue())
return false;
+ int minInt = std::numeric_limits<int>::min();
+ // Avoid negating minimum int as it negates to itself.
+ if (UNLIKELY(nthAValue() == minInt || count == minInt))
esprehn 2016/08/15 16:19:23 how can count be minInt? count is the index of the
+ return false;
+ // Avoid overflow and underflow.
+ if ((UNLIKELY(count > 0 && nthBValue() < std::numeric_limits<int>::min() + count)
+ || (count < 0 && nthBValue() > std::numeric_limits<int>::max() + count)))
+ return false;
return (nthBValue() - count) % (-nthAValue()) == 0;
}
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/CSSSelectorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698