Diff
Modified: branches/safari-603-branch/Source/WebCore/ChangeLog (212047 => 212048)
--- branches/safari-603-branch/Source/WebCore/ChangeLog 2017-02-10 06:35:58 UTC (rev 212047)
+++ branches/safari-603-branch/Source/WebCore/ChangeLog 2017-02-10 06:36:02 UTC (rev 212048)
@@ -1,5 +1,32 @@
2017-02-09 Matthew Hanson <matthew_han...@apple.com>
+ Merge r211621. rdar://problem/30221102
+
+ 2017-02-02 Alex Christensen <achristen...@webkit.org>
+
+ URLParser: Fix parsing invalid IPv4 addresses with non-ASCII characters
+ https://bugs.webkit.org/show_bug.cgi?id=167773
+ <rdar://problem/30221102>
+
+ Reviewed by Ryosuke Niwa.
+
+ If an invalid IPv4 address contains the first syntaxViolation (difference between input and canonicalized URL),
+ an iterator is used to calculate how far we have parsed in the input string to copy all the syntax-violation-free
+ characters into a Vector. If a URL contains only ASCII that doesn't contain anything percent-encoded in the host,
+ there is a fast path to parse ASCII hosts. All my existing invalid IPv4 tests followed this path.
+ If there is a non-ASCII character, we need to use an iterator to the original string instead of an iterator
+ to the string after converting the input string's host to ASCII.
+
+ Covered by a new API test which used to RELEASE_ASSERT.
+
+ * platform/URLParser.cpp:
+ (WebCore::URLParser::parseIPv4Host):
+ (WebCore::URLParser::parseIPv6Host):
+ (WebCore::URLParser::parseHostAndPort):
+ * platform/URLParser.h:
+
+2017-02-09 Matthew Hanson <matthew_han...@apple.com>
+
Merge r211613. rdar://problem/30132707
2017-02-02 Wenson Hsieh <wenson_hs...@apple.com>
Modified: branches/safari-603-branch/Source/WebCore/platform/URLParser.cpp (212047 => 212048)
--- branches/safari-603-branch/Source/WebCore/platform/URLParser.cpp 2017-02-10 06:35:58 UTC (rev 212047)
+++ branches/safari-603-branch/Source/WebCore/platform/URLParser.cpp 2017-02-10 06:36:02 UTC (rev 212048)
@@ -2203,11 +2203,9 @@
return values[exponent];
}
-template<typename CharacterType>
-std::optional<URLParser::IPv4Address> URLParser::parseIPv4Host(CodePointIterator<CharacterType> iterator)
+template<typename CharacterTypeForSyntaxViolation, typename CharacterType>
+std::optional<URLParser::IPv4Address> URLParser::parseIPv4Host(const CodePointIterator<CharacterTypeForSyntaxViolation>& iteratorForSyntaxViolationPosition, CodePointIterator<CharacterType> iterator)
{
- auto hostBegin = iterator;
-
Vector<uint32_t, 4> items;
items.reserveInitialCapacity(4);
bool didSeeSyntaxViolation = false;
@@ -2244,14 +2242,14 @@
return std::nullopt;
if (didSeeSyntaxViolation)
- syntaxViolation(hostBegin);
+ syntaxViolation(iteratorForSyntaxViolationPosition);
for (auto item : items) {
if (item > 255)
- syntaxViolation(hostBegin);
+ syntaxViolation(iteratorForSyntaxViolationPosition);
}
if (UNLIKELY(items.size() != 4))
- syntaxViolation(hostBegin);
+ syntaxViolation(iteratorForSyntaxViolationPosition);
IPv4Address ipv4 = items.takeLast();
for (size_t counter = 0; counter < items.size(); ++counter)
@@ -2318,7 +2316,7 @@
std::optional<URLParser::IPv6Address> URLParser::parseIPv6Host(CodePointIterator<CharacterType> c)
{
ASSERT(*c == '[');
- auto hostBegin = c;
+ const auto hostBegin = c;
advance(c, hostBegin);
if (c.atEnd())
return std::nullopt;
@@ -2623,7 +2621,7 @@
if (isInvalidDomainCharacter(*iterator))
return false;
}
- if (auto address = parseIPv4Host(CodePointIterator<CharacterType>(hostIterator, iterator))) {
+ if (auto address = parseIPv4Host(hostIterator, CodePointIterator<CharacterType>(hostIterator, iterator))) {
serializeIPv4(address.value());
m_url.m_hostEnd = currentPosition(iterator);
if (iterator.atEnd()) {
@@ -2648,7 +2646,7 @@
return true;
}
- auto hostBegin = iterator;
+ const auto hostBegin = iterator;
Vector<LChar, defaultInlineBufferSize> utf8Encoded;
for (; !iterator.atEnd(); ++iterator) {
@@ -2681,7 +2679,7 @@
Vector<LChar, defaultInlineBufferSize>& asciiDomainValue = asciiDomain.value();
const LChar* asciiDomainCharacters = asciiDomainValue.data();
- if (auto address = parseIPv4Host(CodePointIterator<LChar>(asciiDomainValue.begin(), asciiDomainValue.end()))) {
+ if (auto address = parseIPv4Host(hostBegin, CodePointIterator<LChar>(asciiDomainValue.begin(), asciiDomainValue.end()))) {
serializeIPv4(address.value());
m_url.m_hostEnd = currentPosition(iterator);
if (iterator.atEnd()) {
Modified: branches/safari-603-branch/Source/WebCore/platform/URLParser.h (212047 => 212048)
--- branches/safari-603-branch/Source/WebCore/platform/URLParser.h 2017-02-10 06:35:58 UTC (rev 212047)
+++ branches/safari-603-branch/Source/WebCore/platform/URLParser.h 2017-02-10 06:36:02 UTC (rev 212048)
@@ -110,7 +110,7 @@
using IPv4Address = uint32_t;
void serializeIPv4(IPv4Address);
- template<typename CharacterType> std::optional<IPv4Address> parseIPv4Host(CodePointIterator<CharacterType>);
+ template<typename CharacterTypeForSyntaxViolation, typename CharacterType> std::optional<IPv4Address> parseIPv4Host(const CodePointIterator<CharacterTypeForSyntaxViolation>&, CodePointIterator<CharacterType>);
template<typename CharacterType> std::optional<uint32_t> parseIPv4Piece(CodePointIterator<CharacterType>&, bool& syntaxViolation);
using IPv6Address = std::array<uint16_t, 8>;
template<typename CharacterType> std::optional<IPv6Address> parseIPv6Host(CodePointIterator<CharacterType>);
Modified: branches/safari-603-branch/Tools/ChangeLog (212047 => 212048)
--- branches/safari-603-branch/Tools/ChangeLog 2017-02-10 06:35:58 UTC (rev 212047)
+++ branches/safari-603-branch/Tools/ChangeLog 2017-02-10 06:36:02 UTC (rev 212048)
@@ -1,5 +1,20 @@
2017-02-09 Matthew Hanson <matthew_han...@apple.com>
+ Merge r211621. rdar://problem/30221102
+
+ 2017-02-02 Alex Christensen <achristen...@webkit.org>
+
+ URLParser: Fix parsing invalid IPv4 addresses with non-ASCII characters
+ https://bugs.webkit.org/show_bug.cgi?id=167773
+ <rdar://problem/30221102>
+
+ Reviewed by Ryosuke Niwa.
+
+ * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+ (TestWebKitAPI::TEST_F):
+
+2017-02-09 Matthew Hanson <matthew_han...@apple.com>
+
Merge r211254. rdar://problem/30188490
2017-01-26 Chris Dumez <cdu...@apple.com>
Modified: branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp (212047 => 212048)
--- branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp 2017-02-10 06:35:58 UTC (rev 212047)
+++ branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp 2017-02-10 06:36:02 UTC (rev 212048)
@@ -1264,6 +1264,7 @@
shouldFail("http://[1234::ab@]");
shouldFail("http://[1234::ab~]");
shouldFail("http://[2001::1");
+ shouldFail("http://4:b\xE1");
shouldFail("http://[1:2:3:4:5:6:7:8~]/");
shouldFail("http://[a:b:c:d:e:f:g:127.0.0.1]");
shouldFail("http://[a:b:c:d:e:f:g:h:127.0.0.1]");