Skip to content

Commit

Permalink
Fixed #148 as suggested (need to do perf tests but should work correc…
Browse files Browse the repository at this point in the history
…tly)
  • Loading branch information
cowtowncoder committed Aug 13, 2014
1 parent af647e2 commit e997287
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
6 changes: 6 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
@@ -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: ===
------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -3240,7 +3242,7 @@ public static int[] growArrayBy(int[] arr, int more)

/*
/**********************************************************
/* Binary access
/* Internal methods, binary access
/**********************************************************
*/

Expand Down Expand Up @@ -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)));
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down

0 comments on commit e997287

Please sign in to comment.