Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some deserializers throw unexpected NullPointerException when handling invalid input #124

Closed
arthurscchan opened this issue Dec 4, 2023 · 0 comments
Labels
Milestone

Comments

@arthurscchan
Copy link
Contributor

arthurscchan commented Dec 4, 2023

Some methods in the project fail to handle invalid input and throw unexpected NullPointerExcetption. For example, the PrimitiveKVHandler::value() method retrieves a string return from parser.getValueAsString(). If the input provided in the parser is invalid and cannot be converted to a string, it will return null. But the next conditional check calls the length method directly without a null check which could cause an unexpected NullPointerException thrown.

public char value(DeserializationContext ctx, JsonParser parser) throws IOException {
            String valueAsString = parser.getValueAsString();
            if (valueAsString.length() != 1) {
                ......

In GuavaCollectionDeserializer::deserialize() method, it deserialises the provided input and eventually creates a GuavaImmutableCollection object by the upstream GuavaImmutableCollection Builder. In the documentation of Guava, it does mention that in some cases (where the provided input is invalid), NullPointerException can be thrown but it is not specifically handled in the GuavaCollectionDeserializer::deserialize() method and cause unexpected NullPointerException thrown to the user.

    protected T _deserializeContents(JsonParser p, DeserializationContext ctxt)
        throws IOException
    {
       ......
            builder.add(value); // This could thrown NullPointerException according to Guava Javadoc
       ......

Fixes could be implemented by adding null checking or wrapping the thrown NullPointerException with JsonProcessingException to indicate possible invalid data.

We found this issue by OSS-Fuzz and it is reported in https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64610 and https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64629.

@cowtowncoder cowtowncoder changed the title Some methods throw unexpected NullPointerException when handling invalid input Some deserializers throw unexpected NullPointerException when handling invalid input Dec 6, 2023
@cowtowncoder cowtowncoder added this to the 2.17.0 milestone Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants