Changeset 275048 in webkit
- Timestamp:
- Mar 25, 2021, 11:20:58 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
xml/parser/CharacterReferenceParserInlines.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r275046 r275048 1 2021-03-25 Chris Dumez <cdumez@apple.com> 2 3 Source/WebCore/xml/parser/CharacterReferenceParserInlines.h:107:33: runtime error: signed integer overflow: 268435455 * 16 cannot be represented in type 'int' 4 https://bugs.webkit.org/show_bug.cgi?id=223718 5 6 Reviewed by Darin Adler. 7 8 Use Checked<> for the result in consumeCharacterReference() to deal with overflows 9 in a well-defined manner. 10 11 * xml/parser/CharacterReferenceParserInlines.h: 12 (WebCore::consumeCharacterReference): 13 1 14 2021-03-25 John Wilander <wilander@apple.com> 2 15 -
trunk/Source/WebCore/xml/parser/CharacterReferenceParserInlines.h
r248659 r275048 52 52 Named 53 53 } state = Initial; 54 UChar32 result = 0; 55 bool overflow = false; 54 Checked<UChar32, RecordOverflow> result = 0; 56 55 StringBuilder consumedCharacters; 57 56 … … 105 104 Hex: 106 105 if (isASCIIHexDigit(character)) { 107 result = result * 16 + toASCIIHexValue(character); 108 if (result > UCHAR_MAX_VALUE) 109 overflow = true; 106 result *= 16; 107 result += static_cast<UChar32>(toASCIIHexValue(character)); 110 108 break; 111 109 } 112 110 if (character == ';') { 113 111 source.advancePastNonNewline(); 114 decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor( overflow ? 0 : result));112 decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(result.hasOverflowed() ? 0 : result.unsafeGet())); 115 113 return true; 116 114 } 117 115 if (ParserFunctions::acceptMalformed()) { 118 decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor( overflow ? 0 : result));116 decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(result.hasOverflowed() ? 0 : result.unsafeGet())); 119 117 return true; 120 118 } … … 124 122 Decimal: 125 123 if (isASCIIDigit(character)) { 126 result = result * 10 + character - '0'; 127 if (result > UCHAR_MAX_VALUE) 128 overflow = true; 124 result *= 10; 125 result += (character - '0'); 129 126 break; 130 127 } 131 128 if (character == ';') { 132 129 source.advancePastNonNewline(); 133 decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor( overflow ? 0 : result));130 decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(result.hasOverflowed() ? 0 : result.unsafeGet())); 134 131 return true; 135 132 } 136 133 if (ParserFunctions::acceptMalformed()) { 137 decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor( overflow ? 0 : result));134 decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(result.hasOverflowed() ? 0 : result.unsafeGet())); 138 135 return true; 139 136 }
Note:
See TracChangeset
for help on using the changeset viewer.