Skip to content

Commit

Permalink
Gracefully handle malformed hex bytes.
Browse files Browse the repository at this point in the history
  • Loading branch information
joniles committed Jun 14, 2018
1 parent 97c9f27 commit 98abe9a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion RTF Parser Kit/src/com/rtfparserkit/parser/raw/RawRtfParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,22 @@ private void handleCharacterByte(int ch) throws IOException
{
throw new IllegalStateException("Unexpected end of file");
}
b += HexUtils.parseHexDigit(ch);

// Have encountered malformed RTF where only a single hex digit
// has been supplied. e.g. \'AA\'B\'CC so we hit the next \
// rather than getting a hex digit. Try to handle this specific
// case gracefully by unreading the next character and working with
// the single digit we have.
if (ch == '\\')
{
b = b >> 4;
source.unread(ch);
}
else
{
b += HexUtils.parseHexDigit(ch);
}

buffer.add(b);
parsingHex = false;
}
Expand Down

0 comments on commit 98abe9a

Please sign in to comment.