Skip to content

Commit e473e99

Browse files
committed
Fix #540
1 parent b59d232 commit e473e99

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

release-notes/CREDITS-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,8 @@ Alexander Eyers-Taylor (aeyerstaylor@github)
163163
Henrik Gustafsson (gsson@github)
164164
* Reported #516: _inputPtr off-by-one in UTF8StreamJsonParser._parseNumber2()
165165
(2.9.9)
166+
167+
Alex Rebert (alpire@github)
168+
* Reported #540, suggested fix: UTF8StreamJsonParser: fix byte to int conversion for
169+
malformed escapes
170+
(2.9.10)

release-notes/VERSION-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ JSON library.
1414
=== Releases ===
1515
------------------------------------------------------------------------
1616

17+
2.9.10 (not yet released)
18+
19+
#540: UTF8StreamJsonParser: fix byte to int conversion for malformed escapes
20+
(Alex R)
21+
1722
2.9.9 (16-May-2019)
1823

1924
#516: _inputPtr off-by-one in UTF8StreamJsonParser._parseNumber2()

src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3257,7 +3257,7 @@ protected char _decodeEscaped() throws IOException
32573257
_reportInvalidEOF(" in character escape sequence", JsonToken.VALUE_STRING);
32583258
}
32593259
}
3260-
int ch = (int) _inputBuffer[_inputPtr++];
3260+
int ch = _inputBuffer[_inputPtr++] & 0xFF;
32613261
int digit = CharTypes.charToHex(ch);
32623262
if (digit < 0) {
32633263
_reportUnexpectedChar(ch, "expected a hex-digit for character escape sequence");

src/test/java/com/fasterxml/jackson/core/json/TestCharEscaping.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public SerializableString getEscapeSequence(int ch) {
3838
/**********************************************************
3939
*/
4040

41+
private final static JsonFactory JSON_F = new JsonFactory();
42+
4143
public void testMissingEscaping()
4244
throws Exception
4345
{
@@ -150,15 +152,28 @@ public void testWriteLongCustomEscapes() throws Exception
150152
jgen.close();
151153
}
152154

153-
// [Issue#116]
155+
// [core#116]
154156
public void testEscapesForCharArrays() throws Exception {
155-
JsonFactory jf = new JsonFactory();
156157
StringWriter writer = new StringWriter();
157-
JsonGenerator jgen = jf.createGenerator(writer);
158+
JsonGenerator jgen = JSON_F.createGenerator(writer);
158159
// must call #writeString(char[],int,int) and not #writeString(String)
159160
jgen.writeString(new char[] { '\0' }, 0, 1);
160161
jgen.close();
161162
assertEquals("\"\\u0000\"", writer.toString());
162163
}
164+
165+
// [core#540]
166+
public void testInvalidEscape() throws Exception {
167+
JsonParser p = JSON_F.createParser(quote("\\u\u0080...").getBytes("UTF-8"));
168+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
169+
// this is where we should get proper exception
170+
try {
171+
p.getText();
172+
fail("Should not pass");
173+
} catch (JsonParseException e) {
174+
verifyException(e, "Unexpected character");
175+
}
176+
p.close();
177+
}
163178
}
164179

0 commit comments

Comments
 (0)