Skip to content

Commit 98abe9a

Browse files
committed
Gracefully handle malformed hex bytes.
1 parent 97c9f27 commit 98abe9a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

RTF Parser Kit/src/com/rtfparserkit/parser/raw/RawRtfParser.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,22 @@ private void handleCharacterByte(int ch) throws IOException
135135
{
136136
throw new IllegalStateException("Unexpected end of file");
137137
}
138-
b += HexUtils.parseHexDigit(ch);
138+
139+
// Have encountered malformed RTF where only a single hex digit
140+
// has been supplied. e.g. \'AA\'B\'CC so we hit the next \
141+
// rather than getting a hex digit. Try to handle this specific
142+
// case gracefully by unreading the next character and working with
143+
// the single digit we have.
144+
if (ch == '\\')
145+
{
146+
b = b >> 4;
147+
source.unread(ch);
148+
}
149+
else
150+
{
151+
b += HexUtils.parseHexDigit(ch);
152+
}
153+
139154
buffer.add(b);
140155
parsingHex = false;
141156
}

0 commit comments

Comments
 (0)