jackson-dataformat-protobuf denial of service
Description
An eager-allocation denial-of-service in jackson-dataformats-binary's Protobuf parser (latest, 3.2.2 / tools.jackson line), where a bytes length prefix from untrusted input is used to allocate a byte[] before the body is read and without any upper bound. This is the same class as the HIGH-rated CBOR CVE-2020-28491 in this library, which was fixed with a LONGEST_NON_CHUNKED_BINARY guard; the Protobuf parser never received the equivalent guard. Reporter: apvxlab (AppViewX security research).
Per the maintainer's request this advisory now covers only the Protobuf issue. The async-Smile issue that was originally reported here has been filed separately as GHSA-h3c2-2m49-r49w.
File: protobuf/src/main/java/tools/jackson/dataformat/protobuf/ProtobufParser.java (_finishBytes, ~line 2363).
For a length-delimited bytes field, _decodeLength() returns a fully attacker-controlled positive int up to Integer.MAX_VALUE, stored in _decodedLength with no bounds check against the remaining input or the enclosing message end offset (the _currentEndOffset checks apply only to embedded MESSAGE fields, not BYTES). _finishBytes then does byte[] b = new byte[len] before reading any body.
Impact. A ~6-byte message forces a ~2 GB allocation per request; sizes in the few-hundred-MB range reliably exhaust the heap under light concurrency. The resulting OutOfMemoryError is an Error, not a JacksonException, so it escapes the parser contract and crashes request threads (denial of service).
Reproduction (exact bytes).
- Schema
message Foo { optional bytes data = 1; }, POJOclass Foo { public byte[] data; }. - Wire bytes:
{ 0x0A, 0xFF, 0xFF, 0xFF, 0xFF, 0x07 }— tag0x0A(field 1, wire type 2) + varint0x7FFFFFFF(= 2147483647) + zero payload bytes. new ProtobufMapper().readerFor(Foo.class).with(schema).readValue(payload)→_finishBytes(2147483647)runsnew byte[2147483647]before reading the (absent) body → OOM. Use a mid-size length such as the varint for ~300,000,000 for a reliable heap-exhaustion DoS under a few concurrent requests.
Fix. Bound _decodedLength against the remaining input / a configurable maximum before allocating, mirroring the CBOR LONGEST_NON_CHUNKED_BINARY / _finishLongContiguousBytes fix (CVE-2020-28491).
Code-verified against the 3.2.2 source with the exact reproduction input above. Happy to provide a runnable harness and coordinate the fix.
Affected versions
- com.fasterxml.jackson.dataformat:jackson-dataformat-protobufFrom 2.8.0 · through 2.18.11
- com.fasterxml.jackson.dataformat:jackson-dataformat-protobufFrom 2.19.0 · through 2.21.7
- com.fasterxml.jackson.dataformat:jackson-dataformat-protobufFrom 2.22.0 · through 2.22.3
- tools.jackson.dataformat:jackson-dataformat-protobufFrom 3.0.0 · through 3.1.7
- tools.jackson.dataformat:jackson-dataformat-protobufFrom 3.2.0 · through 3.2.3