com.fasterxml.jackson.dataformat.jackson-dataformat-avro denial of service
Description
The Jackson Avro dataformat allocates a byte[] directly from the attacker-controlled Avro bytes length prefix with no bound, so a ~5-byte payload forces a multi-hundred-MB to ~2 GB allocation before any data is read → memory-exhaustion DoS. This is the same class as CVE-2020-28491, which was fixed in the CBOR sibling but never ported to the Avro module. Reporter: apvxlab (AppViewX security research).
PoC executed on com.fasterxml.jackson.dataformat:jackson-dataformat-avro:2.18.2; the identical code is present in tools.jackson.dataformat.avro (3.x HEAD). This is a distinct module/sink from the previously-reported Smile/Protobuf advisory (GHSA-ww35-763r-jg22).
---
Files:
avro/src/main/java/.../avro/deser/JacksonAvroParserImpl.java—decodeBytes()(native decoder, the default).avro/src/main/java/.../avro/apacheimpl/ApacheAvroParserImpl.java—decodeBytes()(Apache-decoder variant,builderWithApacheDecoder()).
When AvroMapper.readValue decodes a field of Avro type bytes, decodeBytes() reads the zig-zag varint length prefix and allocates from it with only a len <= 0 check:
public JsonToken decodeBytes() {
int len = decodeInt(); // attacker-controlled varint, up to Integer.MAX_VALUE
if (len <= 0) { ... }
else {
byte[] b = new byte[len]; // <-- no available-bytes / limit check before allocation
_read(b, 0, len);
...
}
}There is no check of len against the remaining/available input bytes or any StreamReadConstraints limit before the allocation. The safe streaming pattern is used by decodeString/_finishLongString in the very same class and by the CBOR parser (CBORParser._finishBytes diverts len > LONGEST_NON_CHUNKED_BINARY to an incremental ByteArrayBuilder, explicitly citing dataformats-binary#186 / CVE-2020-28491) — but decodeBytes omits it. The Apache-decoder variant additionally bypasses Apache BinaryDecoder.readBytes()'s own SystemLimit guard by calling readInt() + readFixed() and allocating the array itself. The same unguarded allocation underlies decimal fields via decodeBytesDecimal (the FP-length validation runs after the allocation). Reachable by default (AvroFactoryBuilder defaults to the native decoder); the attacker controls the payload while the server owns the schema — the normal Avro trust boundary.
PoC (executed, JDK 17, -Xmx256m):
static class R { public byte[] b; }
Schema schema = new Schema.Parser().parse(
"{\"type\":\"record\",\"name\":\"R\",\"fields\":[{\"name\":\"b\",\"type\":\"bytes\"}]}");
// payload = ONLY the zig-zag varint for len=1_000_000_000 (5 bytes), no data:
byte[] payload = {(byte)0x80,(byte)0xA8,(byte)0xD6,(byte)0xB9,0x07};
new AvroMapper().readerFor(R.class).with(new AvroSchema(schema)).readValue(payload);
// -> new byte[1_000_000_000] -> java.lang.OutOfMemoryError, before _read detects the truncated inputImpact. Resource-exhaustion denial of service (CWE-789/CWE-770). A ~5-byte length prefix declaring up to Integer.MAX_VALUE forces an immediate new byte[len] (up to ~2 GB) — ~400-million-fold amplification. Repeated/concurrent requests reliably cause OutOfMemoryError. Same severity class as the CBOR analog CVE-2020-28491 (High).
Fix. Port the CBOR guard to decodeBytes: cap the eager allocation (e.g. LONGEST_NON_CHUNKED_BINARY) and read larger bytes incrementally via ByteArrayBuilder from real input; apply to both the native and Apache-decoder paths.
Affected versions
- com.fasterxml.jackson.dataformat.jackson-dataformat-avroFrom 2.9.0 · through 2.18.11
- com.fasterxml.jackson.dataformat.jackson-dataformat-avroFrom 2.19.0 · through 2.21.7
- com.fasterxml.jackson.dataformat.jackson-dataformat-avroFrom 2.22.0 · through 2.22.3
- tools.jackson.dataformat.jackson-dataformat-avroFrom 3.0.0 · through 3.1.7
- tools.jackson.dataformat.jackson-dataformat-avroFrom 3.2.0 · through 3.2.3