FasterXML / jackson-dataformats-binary

Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Apache License 2.0
310 stars 133 forks source link

Unexpected `NullPointerException` in `ProtobufParser.currentName()` #460

Closed arthurscchan closed 8 months ago

arthurscchan commented 8 months ago

In the ProtobufParser.currentName() method, there is an invocation of the ProtobufReadContext .getParent() method which could return a null value when the input is malformed and ended unexpectedly because there is no parent read context exists. If the result is null, the code will throw a NullPointerException in the next line when the ProtobufReadContext ::getCurrentName() method is called.

 @Override // since 2.17
    public String currentName() throws IOException
    {
        if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) {
            ProtobufReadContext parent = _parsingContext.getParent();
            return parent.getCurrentName();
        }
        return _parsingContext.getCurrentName();
    }

The suggested fix is to add a null checking after the invocation of the ProtobufReadContext .getParent() method and throw an exception if the return value stored in parent is indeed null.

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