Skip to content

Commit da5365e

Browse files
committed
Fix #578: non-blocking path still had potential problem, but changed method itself to be safer
1 parent db0f586 commit da5365e

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

release-notes/CREDITS-2.x

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ Arnaud Roger (arnaudroger@github)
116116
* Contributed #359: FilteringGeneratorDelegate does not override writeStartObject(Object forValue)
117117
(2.8.8)
118118
119-
Wil Selwood (wselwood@github)
119+
120+
Emily Selwood (emilyselwood@github)
120121
* Reported #382: ArrayIndexOutOfBoundsException from UTF32Reader.read on invalid input
121122
(2.8.9)
123+
* Reported #578: Array index out of bounds in hex lookup
124+
(2.10.1)
122125
123126
Alex Yursha (AlexYursha@github)
124127
* Contributed #312: Add `JsonProcessingException.clearLocation()` to allow clearing

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ JSON library.
2020
(reported by wastevenson@github, fix contributed by Todd O'B
2121
#567: Add `uses` for `ObjectCodec` in module-info
2222
(reported by Marc M)
23+
#578: Array index out of bounds in hex lookup
24+
(reported by Emily S)
2325

2426
2.10.0 (26-Sep-2019)
2527

src/main/java/com/fasterxml/jackson/core/io/CharTypes.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,13 @@ public final class CharTypes
174174
}
175175

176176
/**
177-
* Lookup table for the first 128 Unicode characters (7-bit ASCII)
177+
* Lookup table for the first 256 Unicode characters (ASCII / UTF-8)
178178
* range. For actual hex digits, contains corresponding value;
179179
* for others -1.
180+
*<p>
181+
* NOTE: before 2.10.1, was of size 128, extended for simpler handling
180182
*/
181-
private final static int[] sHexValues = new int[128];
183+
private final static int[] sHexValues = new int[256];
182184
static {
183185
Arrays.fill(sHexValues, -1);
184186
for (int i = 0; i < 10; ++i) {
@@ -223,7 +225,9 @@ public static int[] get7BitOutputEscapes(int quoteChar) {
223225

224226
public static int charToHex(int ch)
225227
{
226-
return (ch > 127) ? -1 : sHexValues[ch];
228+
// 08-Nov-2019, tatu: As per [core#540] and [core#578], changed to
229+
// force masking here so caller need not do that.
230+
return sHexValues[ch & 0xFF];
227231
}
228232

229233
public static void appendQuoted(StringBuilder sb, String content)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3281,10 +3281,10 @@ protected char _decodeEscaped() throws IOException
32813281
_reportInvalidEOF(" in character escape sequence", JsonToken.VALUE_STRING);
32823282
}
32833283
}
3284-
int ch = _inputBuffer[_inputPtr++] & 0xFF;
3284+
int ch = _inputBuffer[_inputPtr++];
32853285
int digit = CharTypes.charToHex(ch);
32863286
if (digit < 0) {
3287-
_reportUnexpectedChar(ch, "expected a hex-digit for character escape sequence");
3287+
_reportUnexpectedChar(ch & 0xFF, "expected a hex-digit for character escape sequence");
32883288
}
32893289
value = (value << 4) | digit;
32903290
}

src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2352,7 +2352,7 @@ private int _decodeSplitEscaped(int value, int bytesRead) throws IOException
23522352
while (true) {
23532353
int digit = CharTypes.charToHex(c);
23542354
if (digit < 0) {
2355-
_reportUnexpectedChar(c, "expected a hex-digit for character escape sequence");
2355+
_reportUnexpectedChar(c & 0xFF, "expected a hex-digit for character escape sequence");
23562356
}
23572357
value = (value << 4) | digit;
23582358
if (++bytesRead == 4) {

0 commit comments

Comments
 (0)