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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/CSSSelectorTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * 1999 Waldo Bastian (bastian@kde.org) 3 * 1999 Waldo Bastian (bastian@kde.org)
4 * 2001 Andreas Schlapbach (schlpbch@iam.unibe.ch) 4 * 2001 Andreas Schlapbach (schlpbch@iam.unibe.ch)
5 * 2001-2003 Dirk Mueller (mueller@kde.org) 5 * 2001-2003 Dirk Mueller (mueller@kde.org)
6 * Copyright (C) 2002, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2002, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2008 David Smith (catfish.man@gmail.com) 7 * Copyright (C) 2008 David Smith (catfish.man@gmail.com)
8 * Copyright (C) 2010 Google Inc. All rights reserved. 8 * Copyright (C) 2010 Google Inc. All rights reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 } 926 }
927 927
928 // a helper function for checking nth-arguments 928 // a helper function for checking nth-arguments
929 bool CSSSelector::RareData::matchNth(int count) 929 bool CSSSelector::RareData::matchNth(int count)
930 { 930 {
931 if (!nthAValue()) 931 if (!nthAValue())
932 return count == nthBValue(); 932 return count == nthBValue();
933 if (nthAValue() > 0) { 933 if (nthAValue() > 0) {
934 if (count < nthBValue()) 934 if (count < nthBValue())
935 return false; 935 return false;
936 // Avoid overflow and underflow.
937 if (UNLIKELY((nthBValue() > 0 && count < std::numeric_limits<int>::min() + nthBValue())
938 || (nthBValue() < 0 && count > std::numeric_limits<int>::max() + nth BValue())))
939 return false;
936 return (count - nthBValue()) % nthAValue() == 0; 940 return (count - nthBValue()) % nthAValue() == 0;
937 } 941 }
938 if (count > nthBValue()) 942 if (count > nthBValue())
939 return false; 943 return false;
944 int minInt = std::numeric_limits<int>::min();
945 // Avoid negating minimum int as it negates to itself.
946 if (UNLIKELY(nthAValue() == minInt || count == minInt))
esprehn 2016/08/15 16:19:23 how can count be minInt? count is the index of the
947 return false;
948 // Avoid overflow and underflow.
949 if ((UNLIKELY(count > 0 && nthBValue() < std::numeric_limits<int>::min() + c ount)
950 || (count < 0 && nthBValue() > std::numeric_limits<int>::max() + count)) )
951 return false;
940 return (nthBValue() - count) % (-nthAValue()) == 0; 952 return (nthBValue() - count) % (-nthAValue()) == 0;
941 } 953 }
942 954
943 } // namespace blink 955 } // namespace blink
OLDNEW
« 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