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

Side by Side Diff: third_party/WebKit/Source/core/css/CSSSelector.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 unified diff | Download patch
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 6 * Copyright (C) 2002, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
7 * reserved. 7 * reserved.
8 * Copyright (C) 2008 David Smith (catfish.man@gmail.com) 8 * Copyright (C) 2008 David Smith (catfish.man@gmail.com)
9 * Copyright (C) 2010 Google Inc. All rights reserved. 9 * Copyright (C) 2010 Google Inc. All rights reserved.
10 * 10 *
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 } 918 }
919 return link_match_type; 919 return link_match_type;
920 } 920 }
921 921
922 void CSSSelector::SetNth(int a, int b) { 922 void CSSSelector::SetNth(int a, int b) {
923 CreateRareData(); 923 CreateRareData();
924 data_.rare_data_->bits_.nth_.a_ = a; 924 data_.rare_data_->bits_.nth_.a_ = a;
925 data_.rare_data_->bits_.nth_.b_ = b; 925 data_.rare_data_->bits_.nth_.b_ = b;
926 } 926 }
927 927
928 bool CSSSelector::MatchNth(int count) const { 928 bool CSSSelector::MatchNth(unsigned count) const {
929 DCHECK(has_rare_data_); 929 DCHECK(has_rare_data_);
930 return data_.rare_data_->MatchNth(count); 930 return data_.rare_data_->MatchNth(count);
931 } 931 }
932 932
933 bool CSSSelector::MatchesPseudoElement() const { 933 bool CSSSelector::MatchesPseudoElement() const {
934 for (const CSSSelector* current = this; current; 934 for (const CSSSelector* current = this; current;
935 current = current->TagHistory()) { 935 current = current->TagHistory()) {
936 if (current->Match() == kPseudoElement) 936 if (current->Match() == kPseudoElement)
937 return true; 937 return true;
938 if (current->Relation() != kSubSelector) 938 if (current->Relation() != kSubSelector)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 CSSSelector::RareData::RareData(const AtomicString& value) 999 CSSSelector::RareData::RareData(const AtomicString& value)
1000 : matching_value_(value), 1000 : matching_value_(value),
1001 serializing_value_(value), 1001 serializing_value_(value),
1002 bits_(), 1002 bits_(),
1003 attribute_(AnyQName()), 1003 attribute_(AnyQName()),
1004 argument_(g_null_atom) {} 1004 argument_(g_null_atom) {}
1005 1005
1006 CSSSelector::RareData::~RareData() {} 1006 CSSSelector::RareData::~RareData() {}
1007 1007
1008 // a helper function for checking nth-arguments 1008 // a helper function for checking nth-arguments
1009 bool CSSSelector::RareData::MatchNth(int count) { 1009 bool CSSSelector::RareData::MatchNth(unsigned unsigned_count) {
1010 // These very large values for aN + B or count can't ever match, so
1011 // give up immediately if we see them.
1012 int max_value = std::numeric_limits<int>::max() / 2;
1013 int min_value = std::numeric_limits<int>::min() / 2;
1014 if (UNLIKELY(unsigned_count > static_cast<unsigned>(max_value) ||
1015 NthAValue() > max_value || NthAValue() < min_value ||
1016 NthBValue() > max_value || NthBValue() < min_value))
1017 return false;
1018
1019 int count = static_cast<int>(unsigned_count);
1010 if (!NthAValue()) 1020 if (!NthAValue())
1011 return count == NthBValue(); 1021 return count == NthBValue();
1012 if (NthAValue() > 0) { 1022 if (NthAValue() > 0) {
1013 if (count < NthBValue()) 1023 if (count < NthBValue())
1014 return false; 1024 return false;
1015 return (count - NthBValue()) % NthAValue() == 0; 1025 return (count - NthBValue()) % NthAValue() == 0;
1016 } 1026 }
1017 if (count > NthBValue()) 1027 if (count > NthBValue())
1018 return false; 1028 return false;
1019 return (NthBValue() - count) % (-NthAValue()) == 0; 1029 return (NthBValue() - count) % (-NthAValue()) == 0;
1020 } 1030 }
1021 1031
1022 } // namespace blink 1032 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSSelector.h ('k') | third_party/WebKit/Source/core/css/CSSSelectorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698