Skip to content

JsonPointer.head() throws StringIndexOutOfBoundsException for valid JSON Pointers #1425

@sergeykad

Description

@sergeykad

Problem Description:
After upgrading to Jackson 2.19.0, valid JsonPointer strings are causing StringIndexOutOfBoundsException when calling head().
The crash happens due to a negative suffixLength calculated in _constructHead().
This was not an issue in previous versions (2.18.x and earlier).

Caused by: java.lang.StringIndexOutOfBoundsException: begin 0, end 14, length 6
    at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4606)
    at java.base/java.lang.String.substring(String.java:2709)
    at com.fasterxml.jackson.core.JsonPointer._constructHead(JsonPointer.java:853)
    at com.fasterxml.jackson.core.JsonPointer.head(JsonPointer.java:606)

Reproducer:

import com.fasterxml.jackson.core.JsonPointer;

public class JsonPointerBugTest {
    public static void main(String[] args) {
        JsonPointer head = JsonPointer.compile("/a/b/0/qwerty");
        head = head.head();
        head = head.head(); // Exception happens here
        System.out.println(head);
    }
}

Version:
Jackson Core 2.19.0

Metadata

Metadata

Assignees

Labels

2.19Issues planned at earliest for 2.19

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions