Skip to content

BytesToNameCanonicalizer can mishandle leading NUL #148

Closed
@rjmac

Description

@rjmac

More from randomized testing: deserializing the document { "\u0000abc" : "a", "abc" : "b" } via the UTF8StreamJsonParser will produce the same text for the second field name as the first. This is because the BytesToNameCanonicalizer will left-pad "abc" with a 0 byte to fit it in an int, which is indistinguishable from a string which really has a leading zero char.

Here's a standalone test case for it:

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;

public class Tokens {
    public static void main(String[] args) throws Exception {
        String[] expectedTexts = { "{", "\u0000abc", "a", "abc", "b", "}" };
        JsonParser parser = new JsonFactory().createParser("{\"\\u0000abc\" : \"a\", \"abc\" : \"b\"}".getBytes());
        for(String expected : expectedTexts) {
            parser.nextToken();
            if(!parser.getText().equals(expected)) throw new Exception(parser.getText() + " != " + expected);
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions