Skip to content

Commit e997287

Browse files
committed
Fixed FasterXML#148 as suggested (need to do perf tests but should work correctly)
1 parent af647e2 commit e997287

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

release-notes/CREDITS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ Steve van Loben Sels
3535
Shay Banon
3636
* Reported #145: NPE at BytesToNameCanonicalizer
3737
(2.4.2)
38+
39+
rjmac@github
40+
* Reported #146: Error while parsing negative floats at the end of the input buffer
41+
(2.4.2)
42+
* Reported #148: BytesToNameCanonicalizer can mishandle leading null byte(s).
43+
(2.5.0)

release-notes/VERSION

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Project: jackson-core
22
Version: 2.5.0 (xx-xxx-2014)
33

4+
#148: BytesToNameCanonicalizer can mishandle leading null byte(s).
5+
(reported by rjmac@github)
6+
47
------------------------------------------------------------------------
58
=== History: ===
69
------------------------------------------------------------------------

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,7 @@ protected Name _parseAposName() throws IOException
19561956
if (qlen >= quads.length) {
19571957
_quadBuffer = quads = growArrayBy(quads, quads.length);
19581958
}
1959-
quads[qlen++] = currQuad;
1959+
quads[qlen++] = pad(currQuad, currQuadBytes);
19601960
}
19611961
Name name = _symbols.findName(quads, qlen);
19621962
if (name == null) {
@@ -1974,6 +1974,7 @@ protected Name _parseAposName() throws IOException
19741974
private final Name findName(int q1, int lastQuadBytes)
19751975
throws JsonParseException
19761976
{
1977+
q1 = pad(q1, lastQuadBytes);
19771978
// Usually we'll find it from the canonical symbol table already
19781979
Name name = _symbols.findName(q1);
19791980
if (name != null) {
@@ -1987,6 +1988,7 @@ private final Name findName(int q1, int lastQuadBytes)
19871988
private final Name findName(int q1, int q2, int lastQuadBytes)
19881989
throws JsonParseException
19891990
{
1991+
q2 = pad(q2, lastQuadBytes);
19901992
// Usually we'll find it from the canonical symbol table already
19911993
Name name = _symbols.findName(q1, q2);
19921994
if (name != null) {
@@ -2004,7 +2006,7 @@ private final Name findName(int[] quads, int qlen, int lastQuad, int lastQuadByt
20042006
if (qlen >= quads.length) {
20052007
_quadBuffer = quads = growArrayBy(quads, quads.length);
20062008
}
2007-
quads[qlen++] = lastQuad;
2009+
quads[qlen++] = pad(lastQuad, lastQuadBytes);
20082010
Name name = _symbols.findName(quads, qlen);
20092011
if (name == null) {
20102012
return addName(quads, qlen, lastQuadBytes);
@@ -3240,7 +3242,7 @@ public static int[] growArrayBy(int[] arr, int more)
32403242

32413243
/*
32423244
/**********************************************************
3243-
/* Binary access
3245+
/* Internal methods, binary access
32443246
/**********************************************************
32453247
*/
32463248

@@ -3355,4 +3357,17 @@ protected final byte[] _decodeBase64(Base64Variant b64variant) throws IOExceptio
33553357
builder.appendThreeBytes(decodedData);
33563358
}
33573359
}
3360+
3361+
/*
3362+
/**********************************************************
3363+
/* Internal methods, other
3364+
/**********************************************************
3365+
*/
3366+
3367+
/**
3368+
* Helper method needed to fix [Issue#148], masking of 0x00 character
3369+
*/
3370+
private final static int pad(int q, int bytes) {
3371+
return (bytes == 4) ? q : (q | (-1 << (bytes << 3)));
3372+
}
33583373
}

src/test/java/com/fasterxml/jackson/core/failing/TestJsonParserSymbols.java renamed to src/test/java/com/fasterxml/jackson/core/json/TestParserSymbols.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
package com.fasterxml.jackson.core.failing;
2-
3-
import java.io.IOException;
1+
package com.fasterxml.jackson.core.json;
42

53
import com.fasterxml.jackson.core.*;
6-
import com.fasterxml.jackson.core.json.ReaderBasedJsonParser;
7-
import com.fasterxml.jackson.core.json.UTF8StreamJsonParser;
84

9-
@SuppressWarnings("serial")
10-
public class TestJsonParserSymbols
5+
public class TestParserSymbols
116
extends com.fasterxml.jackson.test.BaseTest
127
{
8+
// For [Issue#148]
139
public void testSymbolsWithNullBytes() throws Exception {
1410
_testSymbolsWithNull(true);
1511
}
1612

13+
// For [Issue#148]
1714
public void testSymbolsWithNullChars() throws Exception {
1815
_testSymbolsWithNull(false);
1916
}

0 commit comments

Comments
 (0)