WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-167067-20200405000127.patch (text/plain), 12.39 KB, created by
Alexey Shvayka
on 2020-04-04 14:01:29 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Alexey Shvayka
Created:
2020-04-04 14:01:29 PDT
Size:
12.39 KB
patch
obsolete
>Subversion Revision: 259529 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index 88fd32e368266d1e1f0e40386574d419e957296e..649cd8909010f83eaa2f6ac5285381a007341d5b 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,28 @@ >+2020-04-04 Alexey Shvayka <shvaikalesh@gmail.com> >+ >+ Octal escapes should be max 3 digits and syntax errors in Unicode patterns >+ https://bugs.webkit.org/show_bug.cgi?id=167067 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch: >+ >+ a) Adds SyntaxError for octal escapes in Unicode patterns, while preserving /\0/u >+ being parsed as null character escape. Grammar: https://tc39.es/ecma262/#prod-CharacterEscape >+ >+ b) Limits consumeOctal() to 3 digits only, preventing it from consuming leading zeros. >+ Grammar: https://tc39.es/ecma262/#prod-annexB-LegacyOctalEscapeSequence >+ >+ Both changes align JSC with V8 and SpiderMonkey. >+ >+ * yarr/YarrErrorCode.cpp: >+ (JSC::Yarr::errorMessage): >+ (JSC::Yarr::errorToThrow): >+ * yarr/YarrErrorCode.h: >+ * yarr/YarrParser.h: >+ (JSC::Yarr::Parser::parseEscape): >+ (JSC::Yarr::Parser::consumeOctal): >+ > 2020-04-03 Yusuke Suzuki <ysuzuki@apple.com> > > [JSC] canonicalizeLocaleList should gracefully throw OOM error if input + error message is too large >diff --git a/Source/JavaScriptCore/yarr/YarrErrorCode.cpp b/Source/JavaScriptCore/yarr/YarrErrorCode.cpp >index c86929827e1d8b5e0e4950fef60d9b4947252dea..8c7f5fc73a28a3ed6071868bcf579d0ccafbb7d1 100644 >--- a/Source/JavaScriptCore/yarr/YarrErrorCode.cpp >+++ b/Source/JavaScriptCore/yarr/YarrErrorCode.cpp >@@ -56,6 +56,7 @@ const char* errorMessage(ErrorCode error) > REGEXP_ERROR_PREFIX "invalid backreference for Unicode pattern", // InvalidBackreference > REGEXP_ERROR_PREFIX "invalid \\k<> named backreference", // InvalidNamedBackReference > REGEXP_ERROR_PREFIX "invalid escaped character for Unicode pattern", // InvalidIdentityEscape >+ REGEXP_ERROR_PREFIX "invalid octal escape for Unicode pattern", // InvalidOctalEscape > REGEXP_ERROR_PREFIX "invalid \\c escape for Unicode pattern", // InvalidControlLetterEscape > REGEXP_ERROR_PREFIX "invalid property expression", // InvalidUnicodePropertyExpression > REGEXP_ERROR_PREFIX "too many nested disjunctions", // TooManyDisjunctions >@@ -92,6 +93,7 @@ JSObject* errorToThrow(JSGlobalObject* globalObject, ErrorCode error) > case ErrorCode::InvalidBackreference: > case ErrorCode::InvalidNamedBackReference: > case ErrorCode::InvalidIdentityEscape: >+ case ErrorCode::InvalidOctalEscape: > case ErrorCode::InvalidControlLetterEscape: > case ErrorCode::InvalidUnicodePropertyExpression: > case ErrorCode::OffsetTooLarge: >diff --git a/Source/JavaScriptCore/yarr/YarrErrorCode.h b/Source/JavaScriptCore/yarr/YarrErrorCode.h >index 2d89588cf9dc0c358d19babd97260495f47abc20..d277fcbc4dca83bd883097c7c003ad3679bb55f9 100644 >--- a/Source/JavaScriptCore/yarr/YarrErrorCode.h >+++ b/Source/JavaScriptCore/yarr/YarrErrorCode.h >@@ -55,6 +55,7 @@ enum class ErrorCode : uint8_t { > InvalidBackreference, > InvalidNamedBackReference, > InvalidIdentityEscape, >+ InvalidOctalEscape, > InvalidControlLetterEscape, > InvalidUnicodePropertyExpression, > TooManyDisjunctions, >diff --git a/Source/JavaScriptCore/yarr/YarrParser.h b/Source/JavaScriptCore/yarr/YarrParser.h >index 8130e0a5c2fa1cdbcc7d13f3baaa02b5509fdda4..8e16f1303d0915942138fec6cd22c9935344beb0 100644 >--- a/Source/JavaScriptCore/yarr/YarrParser.h >+++ b/Source/JavaScriptCore/yarr/YarrParser.h >@@ -322,6 +322,23 @@ private: > delegate.atomBuiltInCharacterClass(BuiltInCharacterClassID::WordClassID, true); > break; > >+ case '0': { >+ consume(); >+ >+ if (!peekIsDigit()) { >+ delegate.atomPatternCharacter(0); >+ break; >+ } >+ >+ if (m_isUnicode) { >+ m_errorCode = ErrorCode::InvalidOctalEscape; >+ break; >+ } >+ >+ delegate.atomPatternCharacter(consumeOctal(2)); >+ break; >+ } >+ > // DecimalEscape > case '1': > case '2': >@@ -332,7 +349,7 @@ private: > case '7': > case '8': > case '9': { >- // To match Firefox, we parse an invalid backreference in the range [1-7] as an octal escape. >+ // For non-Unicode patterns, invalid backreferences are parsed as octal or decimal escapes. > // First, try to parse this as backreference. > if (!inCharacterClass) { > ParseState state = saveState(); >@@ -345,22 +362,20 @@ private: > } > > restoreState(state); >+ if (m_isUnicode) { >+ m_errorCode = ErrorCode::InvalidBackreference; >+ break; >+ } > } > >- // Not a backreference, and not octal. Just a number. >- if (peek() >= '8') { >- delegate.atomPatternCharacter(consume()); >+ if (m_isUnicode) { >+ m_errorCode = ErrorCode::InvalidOctalEscape; > break; > } > >- // Fall-through to handle this as an octal escape. >- FALLTHROUGH; >- } >- >- // Octal escape >- case '0': >- delegate.atomPatternCharacter(consumeOctal()); >+ delegate.atomPatternCharacter(peek() < '8' ? consumeOctal(3) : consume()); > break; >+ } > > // ControlEscape > case 'f': >@@ -1066,14 +1081,13 @@ private: > return n.hasOverflowed() ? quantifyInfinite : n.unsafeGet(); > } > >- unsigned consumeOctal() >+ // https://tc39.es/ecma262/#prod-annexB-LegacyOctalEscapeSequence >+ unsigned consumeOctal(unsigned count) > { >- ASSERT(WTF::isASCIIOctalDigit(peek())); >- >- unsigned n = consumeDigit(); >- while (n < 32 && !atEndOfPattern() && WTF::isASCIIOctalDigit(peek())) >- n = n * 8 + consumeDigit(); >- return n; >+ unsigned octal = 0; >+ while (count-- && octal < 32 && !atEndOfPattern() && WTF::isASCIIOctalDigit(peek())) >+ octal = octal * 8 + consumeDigit(); >+ return octal; > } > > bool tryConsume(UChar ch) >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 3b6b4aa9cc366e07ae33d94d6d0d010a7a86ace9..2b9ed457248bec8d91be83318d93d23fe29a2329 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,13 @@ >+2020-04-04 Alexey Shvayka <shvaikalesh@gmail.com> >+ >+ Octal escapes should be max 3 digits and syntax errors in Unicode patterns >+ https://bugs.webkit.org/show_bug.cgi?id=167067 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * js/regexp-unicode-expected.txt: >+ * js/script-tests/regexp-unicode.js: >+ > 2020-04-03 Truitt Savell <tsavell@apple.com> > > Unreviewed, reverting r259440. >diff --git a/LayoutTests/js/regexp-unicode-expected.txt b/LayoutTests/js/regexp-unicode-expected.txt >index a2e1d9ed79cedcad59c303f6832a0c8705f8e2c1..0549e3314648e49c8646801d82d880d58dd12935 100644 >--- a/LayoutTests/js/regexp-unicode-expected.txt >+++ b/LayoutTests/js/regexp-unicode-expected.txt >@@ -183,6 +183,9 @@ PASS r = new RegExp("ð {2147483648}", "u") threw exception SyntaxError: Invali > PASS /{/u threw exception SyntaxError: Invalid regular expression: incomplete {} quantifier for Unicode pattern. > PASS /[a-\d]/u threw exception SyntaxError: Invalid regular expression: invalid range in character class for Unicode pattern. > PASS /]/u threw exception SyntaxError: Invalid regular expression: unmatched ] or } bracket for Unicode pattern. >+PASS /\5/u threw exception SyntaxError: Invalid regular expression: invalid backreference for Unicode pattern. >+PASS /\01/u threw exception SyntaxError: Invalid regular expression: invalid octal escape for Unicode pattern. >+PASS /[\23]/u threw exception SyntaxError: Invalid regular expression: invalid octal escape for Unicode pattern. > PASS /\c9/u threw exception SyntaxError: Invalid regular expression: invalid \c escape for Unicode pattern. > PASS r = new RegExp("\\-", "u") threw exception SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern. > PASS r = new RegExp("\\a", "u") threw exception SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern. >diff --git a/LayoutTests/js/script-tests/regexp-unicode.js b/LayoutTests/js/script-tests/regexp-unicode.js >index 71dcec2a9b1fb5d54f83ced718019ad880537c51..a97a64954c0b6019c847106955e9cfe9cce60664 100644 >--- a/LayoutTests/js/script-tests/regexp-unicode.js >+++ b/LayoutTests/js/script-tests/regexp-unicode.js >@@ -232,6 +232,9 @@ shouldThrow('r = new RegExp("\u{10405}{2147483648}", "u")', '"SyntaxError: Inval > shouldThrow('/{/u', '"SyntaxError: Invalid regular expression: incomplete {} quantifier for Unicode pattern"'); > shouldThrow('/[a-\\d]/u', '"SyntaxError: Invalid regular expression: invalid range in character class for Unicode pattern"'); > shouldThrow('/]/u', '"SyntaxError: Invalid regular expression: unmatched ] or } bracket for Unicode pattern"'); >+shouldThrow('/\\5/u', '"SyntaxError: Invalid regular expression: invalid backreference for Unicode pattern"'); >+shouldThrow('/\\01/u', '"SyntaxError: Invalid regular expression: invalid octal escape for Unicode pattern"'); >+shouldThrow('/[\\23]/u', '"SyntaxError: Invalid regular expression: invalid octal escape for Unicode pattern"'); > shouldThrow('/\\c9/u', '"SyntaxError: Invalid regular expression: invalid \\\\c escape for Unicode pattern"'); > > var invalidEscapeException = "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern"; >diff --git a/JSTests/ChangeLog b/JSTests/ChangeLog >index f4e92eb6c34327ad74fdcd26fcfc805ab89b2e19..2715796867b3314fd9626fe28bd56a53ac7011f6 100644 >--- a/JSTests/ChangeLog >+++ b/JSTests/ChangeLog >@@ -1,3 +1,12 @@ >+2020-04-04 Alexey Shvayka <shvaikalesh@gmail.com> >+ >+ Octal escapes should be max 3 digits and syntax errors in Unicode patterns >+ https://bugs.webkit.org/show_bug.cgi?id=167067 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * test262/expectations.yaml: Mark 4 test cases as passing. >+ > 2020-04-03 Alexey Shvayka <shvaikalesh@gmail.com> > > Update test262 to commit 62b8fce38971 >diff --git a/JSTests/test262/expectations.yaml b/JSTests/test262/expectations.yaml >index e0ec70798d60b05702b5a2e9da2b4f18fb0c7fd0..32d38eb9f8b546858d15fc403d98ad1584183269 100644 >--- a/JSTests/test262/expectations.yaml >+++ b/JSTests/test262/expectations.yaml >@@ -609,9 +609,6 @@ test/annexB/language/global-code/switch-dflt-global-skip-early-err-try.js: > default: 'Test262Error: An initialized binding is not created prior to evaluation Expected a ReferenceError to be thrown but no exception was thrown at all' > test/annexB/language/global-code/switch-dflt-global-skip-early-err.js: > default: "SyntaxError: Cannot declare a function that shadows a let/const/class/function variable 'f' in strict mode." >-test/annexB/language/literals/regexp/legacy-octal-escape.js: >- default: "TypeError: null is not an object (evaluating '/\\0111/.exec('\\x091')[0]')" >- strict mode: "TypeError: null is not an object (evaluating '/\\0111/.exec('\\x091')[0]')" > test/annexB/language/statements/for-of/iterator-close-return-emulates-undefined-throws-when-called.js: > default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all' > strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all' >@@ -1702,9 +1699,6 @@ test/built-ins/RegExp/prototype/unicode/cross-realm.js: > test/built-ins/RegExp/quantifier-integer-limit.js: > default: 'SyntaxError: Invalid regular expression: number too large in {} quantifier' > strict mode: 'SyntaxError: Invalid regular expression: number too large in {} quantifier' >-test/built-ins/RegExp/unicode_restricted_octal_escape.js: >- default: 'Test262Error: RegExp("[\1]", "u"): Expected a SyntaxError to be thrown but no exception was thrown at all' >- strict mode: 'Test262Error: RegExp("[\1]", "u"): Expected a SyntaxError to be thrown but no exception was thrown at all' > test/built-ins/Set/proto-from-ctor-realm.js: > default: 'Test262Error: Expected SameValue(«[object Set]», «[object Set]») to be true' > strict mode: 'Test262Error: Expected SameValue(«[object Set]», «[object Set]») to be true'
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 167067
:
395460
|
395478