diff --git a/release-notes/CREDITS b/release-notes/CREDITS index eb815dfee7..a8b3859cf4 100644 --- a/release-notes/CREDITS +++ b/release-notes/CREDITS @@ -35,3 +35,9 @@ Steve van Loben Sels Shay Banon * Reported #145: NPE at BytesToNameCanonicalizer (2.4.2) + +rjmac@github + * Reported #146: Error while parsing negative floats at the end of the input buffer + (2.4.2) + * Reported #148: BytesToNameCanonicalizer can mishandle leading null byte(s). + (2.5.0) diff --git a/release-notes/VERSION b/release-notes/VERSION index c22574f861..a5e277215b 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -1,6 +1,9 @@ Project: jackson-core Version: 2.5.0 (xx-xxx-2014) +#148: BytesToNameCanonicalizer can mishandle leading null byte(s). + (reported by rjmac@github) + ------------------------------------------------------------------------ === History: === ------------------------------------------------------------------------ diff --git a/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java b/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java index 4d8067d45c..24cb7145e0 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java +++ b/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java @@ -1956,7 +1956,7 @@ protected Name _parseAposName() throws IOException if (qlen >= quads.length) { _quadBuffer = quads = growArrayBy(quads, quads.length); } - quads[qlen++] = currQuad; + quads[qlen++] = pad(currQuad, currQuadBytes); } Name name = _symbols.findName(quads, qlen); if (name == null) { @@ -1974,6 +1974,7 @@ protected Name _parseAposName() throws IOException private final Name findName(int q1, int lastQuadBytes) throws JsonParseException { + q1 = pad(q1, lastQuadBytes); // Usually we'll find it from the canonical symbol table already Name name = _symbols.findName(q1); if (name != null) { @@ -1987,6 +1988,7 @@ private final Name findName(int q1, int lastQuadBytes) private final Name findName(int q1, int q2, int lastQuadBytes) throws JsonParseException { + q2 = pad(q2, lastQuadBytes); // Usually we'll find it from the canonical symbol table already Name name = _symbols.findName(q1, q2); if (name != null) { @@ -2004,7 +2006,7 @@ private final Name findName(int[] quads, int qlen, int lastQuad, int lastQuadByt if (qlen >= quads.length) { _quadBuffer = quads = growArrayBy(quads, quads.length); } - quads[qlen++] = lastQuad; + quads[qlen++] = pad(lastQuad, lastQuadBytes); Name name = _symbols.findName(quads, qlen); if (name == null) { return addName(quads, qlen, lastQuadBytes); @@ -3240,7 +3242,7 @@ public static int[] growArrayBy(int[] arr, int more) /* /********************************************************** - /* Binary access + /* Internal methods, binary access /********************************************************** */ @@ -3355,4 +3357,17 @@ protected final byte[] _decodeBase64(Base64Variant b64variant) throws IOExceptio builder.appendThreeBytes(decodedData); } } + + /* + /********************************************************** + /* Internal methods, other + /********************************************************** + */ + + /** + * Helper method needed to fix [Issue#148], masking of 0x00 character + */ + private final static int pad(int q, int bytes) { + return (bytes == 4) ? q : (q | (-1 << (bytes << 3))); + } } diff --git a/src/test/java/com/fasterxml/jackson/core/failing/TestJsonParserSymbols.java b/src/test/java/com/fasterxml/jackson/core/json/TestParserSymbols.java similarity index 82% rename from src/test/java/com/fasterxml/jackson/core/failing/TestJsonParserSymbols.java rename to src/test/java/com/fasterxml/jackson/core/json/TestParserSymbols.java index 97c9ea33e9..dd0c271c7f 100644 --- a/src/test/java/com/fasterxml/jackson/core/failing/TestJsonParserSymbols.java +++ b/src/test/java/com/fasterxml/jackson/core/json/TestParserSymbols.java @@ -1,19 +1,16 @@ -package com.fasterxml.jackson.core.failing; - -import java.io.IOException; +package com.fasterxml.jackson.core.json; import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.core.json.ReaderBasedJsonParser; -import com.fasterxml.jackson.core.json.UTF8StreamJsonParser; -@SuppressWarnings("serial") -public class TestJsonParserSymbols +public class TestParserSymbols extends com.fasterxml.jackson.test.BaseTest { + // For [Issue#148] public void testSymbolsWithNullBytes() throws Exception { _testSymbolsWithNull(true); } + // For [Issue#148] public void testSymbolsWithNullChars() throws Exception { _testSymbolsWithNull(false); }