|
4 | 4 | import com.fasterxml.jackson.core.JsonPointer;
|
5 | 5 |
|
6 | 6 | // For https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=51806
|
7 |
| -// (via databind, but we don't need that) |
| 7 | +// (reported as [core#818] |
8 | 8 | public class Fuzz51806JsonPointerParseTest extends BaseTest
|
9 | 9 | {
|
10 | 10 | // Before fix, looks like this is enough to cause StackOverflowError
|
11 | 11 | private final static int TOO_DEEP_PATH = 6000;
|
12 | 12 |
|
13 |
| - // Verify that very deep/long (by number of segments) JsonPointer |
14 |
| - // may still be parsed ok |
15 |
| - public void testJsonPointerParseTail() throws Exception |
| 13 | + // Verify that a very deep/long (by number of segments) JsonPointer |
| 14 | + // may still be parsed ok, for "simple" case (no quoted chars) |
| 15 | + public void testJsonPointerParseTailSimple() |
16 | 16 | {
|
17 |
| - JsonPointer p = JsonPointer.compile(_generatePath(TOO_DEEP_PATH)); |
| 17 | + _testJsonPointer(_generatePath(TOO_DEEP_PATH, false)); |
| 18 | + } |
| 19 | + |
| 20 | + public void testJsonPointerParseTailWithQuoted() |
| 21 | + { |
| 22 | + _testJsonPointer(_generatePath(TOO_DEEP_PATH, true)); |
| 23 | + } |
| 24 | + |
| 25 | + private void _testJsonPointer(String pathExpr) |
| 26 | + { |
| 27 | + JsonPointer p = JsonPointer.compile(pathExpr); |
18 | 28 | assertNotNull(p);
|
| 29 | + // But also verify it didn't change |
| 30 | + assertEquals(pathExpr, p.toString()); |
19 | 31 | }
|
20 | 32 |
|
21 |
| - private String _generatePath(int depth) { |
| 33 | + private String _generatePath(int depth, boolean escaped) { |
22 | 34 | StringBuilder sb = new StringBuilder(4 * depth);
|
23 | 35 | for (int i = 0; i < depth; ++i) {
|
24 |
| - sb.append("/a").append(depth); |
| 36 | + sb.append('/') |
| 37 | + .append((char) ('a' + i%25)) |
| 38 | + .append(i); |
| 39 | + |
| 40 | + if (escaped) { |
| 41 | + switch (i & 7) { |
| 42 | + case 1: |
| 43 | + sb.append("~0x"); |
| 44 | + break; |
| 45 | + case 4: |
| 46 | + sb.append("~1y"); |
| 47 | + break; |
| 48 | + } |
| 49 | + } |
25 | 50 | }
|
26 | 51 | return sb.toString();
|
27 | 52 | }
|
|
0 commit comments