⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 275048 in webkit


Ignore:
Timestamp:
Mar 25, 2021, 11:20:58 AM (5 years ago)
Author:
Chris Dumez
Message:

Source/WebCore/xml/parser/CharacterReferenceParserInlines.h:107:33: runtime error: signed integer overflow: 268435455 * 16 cannot be represented in type 'int'
https://bugs.webkit.org/show_bug.cgi?id=223718

Reviewed by Darin Adler.

Use Checked<> for the result in consumeCharacterReference() to deal with overflows
in a well-defined manner.

  • xml/parser/CharacterReferenceParserInlines.h:

(WebCore::consumeCharacterReference):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r275046 r275048  
     12021-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
    1142021-03-25  John Wilander  <wilander@apple.com>
    215
  • trunk/Source/WebCore/xml/parser/CharacterReferenceParserInlines.h

    r248659 r275048  
    5252        Named
    5353    } state = Initial;
    54     UChar32 result = 0;
    55     bool overflow = false;
     54    Checked<UChar32, RecordOverflow> result = 0;
    5655    StringBuilder consumedCharacters;
    5756   
     
    105104        Hex:
    106105            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));
    110108                break;
    111109            }
    112110            if (character == ';') {
    113111                source.advancePastNonNewline();
    114                 decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(overflow ? 0 : result));
     112                decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(result.hasOverflowed() ? 0 : result.unsafeGet()));
    115113                return true;
    116114            }
    117115            if (ParserFunctions::acceptMalformed()) {
    118                 decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(overflow ? 0 : result));
     116                decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(result.hasOverflowed() ? 0 : result.unsafeGet()));
    119117                return true;
    120118            }
     
    124122        Decimal:
    125123            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');
    129126                break;
    130127            }
    131128            if (character == ';') {
    132129                source.advancePastNonNewline();
    133                 decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(overflow ? 0 : result));
     130                decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(result.hasOverflowed() ? 0 : result.unsafeGet()));
    134131                return true;
    135132            }
    136133            if (ParserFunctions::acceptMalformed()) {
    137                 decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(overflow ? 0 : result));
     134                decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(result.hasOverflowed() ? 0 : result.unsafeGet()));
    138135                return true;
    139136            }
Note: See TracChangeset for help on using the changeset viewer.