From ce25ff4b58066abb1fb6aef66756e3018e940f3b Mon Sep 17 00:00:00 2001 From: "Robert J. Macomber" Date: Sun, 10 Aug 2014 21:21:37 -0700 Subject: [PATCH] When caching names from bytes, pad with 0xff instead of 0 0xff can't occur in well-formed UTF-8, so it will not cause false-positives. Might resolve #148 --- .../jackson/core/json/UTF8StreamJsonParser.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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..b42400d144 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java +++ b/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java @@ -1960,6 +1960,7 @@ protected Name _parseAposName() throws IOException } Name name = _symbols.findName(quads, qlen); if (name == null) { + quads[qlen - 1] = pad(quads[qlen - 1], currQuadBytes); name = addName(quads, qlen, currQuadBytes); } return name; @@ -1971,10 +1972,16 @@ protected Name _parseAposName() throws IOException /********************************************************** */ + private int pad(int q, int bytes) { + if(bytes == 4) return q; + return q | (-1 << (bytes << 3)); + } + private final Name findName(int q1, int lastQuadBytes) throws JsonParseException { // Usually we'll find it from the canonical symbol table already + q1 = pad(q1, lastQuadBytes); Name name = _symbols.findName(q1); if (name != null) { return name; @@ -1988,6 +1995,7 @@ private final Name findName(int q1, int q2, int lastQuadBytes) throws JsonParseException { // Usually we'll find it from the canonical symbol table already + q2 = pad(q2, lastQuadBytes); Name name = _symbols.findName(q1, q2); if (name != null) { return name; @@ -2004,7 +2012,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);