Skip to content

Commit 6a63752

Browse files
committed
Fixed #191
1 parent 8fbde68 commit 6a63752

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

release-notes/VERSION

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ JSON library.
1414
=== Releases ===
1515
------------------------------------------------------------------------
1616

17+
2.5.3 (not released yet)
18+
19+
#191: Longest collision chain in symbol table now exceeds maximum -- suspect a DoS attack
20+
(reported by Paul D)
21+
1722
2.5.2 (29-Mar-2015)
1823

1924
#181: Failure parsing -Infinity on buffer boundary

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ private String _parseName2(int startPtr, int hash, int endChar) throws IOExcepti
13021302
}
13031303
}
13041304
}
1305-
hash = (hash * CharsToNameCanonicalizer.HASH_MULT) + i;
1305+
hash = (hash * CharsToNameCanonicalizer.HASH_MULT) + c;
13061306
// Ok, let's add char to output:
13071307
outBuf[outPtr++] = c;
13081308

@@ -1318,7 +1318,6 @@ private String _parseName2(int startPtr, int hash, int endChar) throws IOExcepti
13181318
char[] buf = tb.getTextBuffer();
13191319
int start = tb.getTextOffset();
13201320
int len = tb.size();
1321-
13221321
return _symbols.findSymbol(buf, start, len, hash);
13231322
}
13241323
}

src/test/java/com/fasterxml/jackson/core/sym/TestSymbolTables.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,41 @@ public void testShortNameCollisionsViaParser() throws Exception
152152
p.close();
153153
}
154154

155+
// [core#191]
156+
public void testShortQuotedDirectChars() throws IOException
157+
{
158+
final int COUNT = 400;
159+
160+
CharsToNameCanonicalizer symbols = CharsToNameCanonicalizer.createRoot(1);
161+
for (int i = 0; i < COUNT; ++i) {
162+
String id = String.format("\\u%04x", i);
163+
char[] ch = id.toCharArray();
164+
symbols.findSymbol(ch, 0, ch.length, symbols.calcHash(id));
165+
}
166+
assertEquals(COUNT, symbols.size());
167+
assertEquals(1024, symbols.bucketCount());
168+
169+
assertEquals(112, symbols.collisionCount());
170+
assertEquals(2, symbols.maxCollisionLength());
171+
}
172+
173+
public void testShortQuotedDirectBytes() throws IOException
174+
{
175+
final int COUNT = 400;
176+
BytesToNameCanonicalizer symbols =
177+
BytesToNameCanonicalizer.createRoot(1).makeChild(JsonFactory.Feature.collectDefaults());
178+
for (int i = 0; i < COUNT; ++i) {
179+
String id = String.format("\\u%04x", i);
180+
int[] quads = BytesToNameCanonicalizer.calcQuads(id.getBytes("UTF-8"));
181+
symbols.addName(id, quads, quads.length);
182+
}
183+
assertEquals(COUNT, symbols.size());
184+
assertEquals(1024, symbols.bucketCount());
185+
186+
assertEquals(44, symbols.collisionCount());
187+
assertEquals(2, symbols.maxCollisionLength());
188+
}
189+
155190
// [core#191]
156191
public void testShortNameCollisionsDirect() throws IOException
157192
{
@@ -196,14 +231,7 @@ private String _shortDoc191() {
196231
if (i > 0) {
197232
sb.append(",\n");
198233
}
199-
sb.append('"');
200-
char c = (char) i;
201-
if (Character.isLetterOrDigit(c)) {
202-
sb.append((char) i);
203-
} else {
204-
sb.append(String.format("\\u%04x", i));
205-
}
206-
sb.append("\" : "+i);
234+
sb.append(String.format("\"\\u%04x\" : %d", i, i));
207235
}
208236
sb.append("}\n");
209237
return sb.toString();

0 commit comments

Comments
 (0)