-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The DataSize field was on the wire. The decoder did not read it.\n\n`Batch` is the protobuf wrapper Klever-Go uses for every gossip-broadcast group of transactions, block bodies, and trie nodes. The generated struct has five wire fields:\n\n```go\ntype Batch struct {\n Data [][]byte `protobuf:\"bytes,1,rep,name=Data...\"`\n Stream []byte `protobuf:\"bytes,2,opt,name=Stream...\"`\n IsCompressed bool `protobuf:\"varint,3,opt,name=IsCompressed...\"`\n Algo CType `protobuf:\"varint,4,opt,name=Algo...\"`\n DataSize int32 `protobuf:\"varint,5,opt,name=DataSize...\"`\n ...\n}\n```\n\n`Compress` writes `DataSize` on the way out, after marshaling and right before the function returns:\n\n```go\nba.Stream = make([]byte, len(result))\ncopy(ba.Stream, result)\nba.IsCompressed = true\nba.DataSize = int32(len(data)) // #nosec G115\nba.Data = nil\nreturn nil\n```\n\n`len(data)` is the length of the marshaled batch before gzip ran. Every batch the cluster sends advertises, in its own wire-visible header, the size it will be after decompression. The protocol declares it.\n\n`Decompress` ran on every batch the cluster received. At v1.7.16 the gzip branch reads:\n\n```go\n} else {\n result, err = decompressGzip(ba.Stream)\n if err != nil {\n return err\n }\n}\n\n// decode\nerr = m.Unmarshal(ba, result)\n```\n\nNo reference to `ba.DataSize`. The LZ4 branch threads `ba.DataSize` into `decompressLZ4(dataSize int32, data []byte)`, but the LZ4 path is a stub that falls through to gzip and the parameter is unused:\n\n```go\nfunc decompressLZ4(dataSize int32, data []byte) ([]byte, error) {\n return decompressGzip(data)\n /*output := make([]byte, dataSize)\n _, err := lz4.Uncompress(output, data)\n ...*/\n}\n```\n\nThe commented-out implementation is testimony. `output := make([]byte, dataSize)` is the line the original author wrote when they intended to use `dataSize`. They left it inside a comment alongside the replacement, which does not. `make([]byte, dataSize)` against an attacker-controlled `dataSize` is one DoS primitive; the replacement shipped a different one. The choice was between two paths, both reachable by any peer on the topic, neither bounded against the same protocol field that arrived alongside the payload.\n\n`decompressGzip` itself does the rest:\n\n```go\nfunc decompressGzip(data []byte) ([]byte, error) {\n rdata := bytes.NewReader(data)\n\n reader, err := gzip.NewReader(rdata)\n if err != nil {\n return nil, err\n }\n\n result, err := io.ReadAll(reader)\n if err != nil {\n return nil, err\n }\n ...\n}\n```\n\n`io.ReadAll(reader)` against a gzip stream the attacker assembled. No limit. No bound. No reference to `DataSize`. The gzip format permits 1024:1 compression ratios trivially and pushes well past that with a tuned dictionary; the CVE description names \"multi-gigabyte heaps from a sub-50 KiB gossip payload\" and the fix commit's regression suite includes a dedicated \"high-ratio\" test for the same primitive.\n\nThe size the sender wrote into field 5 was sitting on the byte stream the decoder owned. The decoder did not look.\n\n## The 1 MiB ceiling was on the bus. The decompressor was downstream of it.\n\n`MultiDataInterceptor.ProcessReceivedMessage` is the entry point that lands every multi-data batch arriving on a topic. At v1.7.16, the order of operations was:\n\n```go\nfunc (mdi *MultiDataInterceptor) ProcessReceivedMessage(message p2p.MessageP2P, fromConnectedPeer core.PeerID) error {\n err := mdi.preProcessMessage(message, fromConnectedPeer)\n if err != nil {\n return err\n }\n b := batch.Batch{}\n err = mdi.marshalizer.Unmarshal(&b, message.Data())\n ...\n if b.IsCompressed {\n err = b.Decompress(mdi.marshalizer)\n if err != nil {\n log.Error(\"MultiDataInterceptor.ProcessReceivedMessage\", \"err\", err.Error())\n return err\n }\n }\n\n multiDataBuff := b.Data\n lenMultiData := len(multiDataBuff)\n ...\n err = mdi.antifloodHandler.CanProcessMessagesOnTopic(\n fromConnectedPeer,\n mdi.topic,\n uint32(lenMultiData),\n uint64(len(message.Data())),\n message.SeqNo(),\n )\n```\n\nTwo anti-flood frames bracket the decompression step. `preProcessMessage`, above, ran against the wire-sized message. The wire was capped at 1 MiB by libp2p's `pubsub.DefaultMaxMessageSize`. `CanProcessMessagesOnTopic`, below, ran against the post-decompression `lenMultiData`. By the time `CanProcessMessagesOnTopic` returned its answer, the gzip stream had already inflated and the goroutine was holding the full inflated payload as live heap.\n\nThe anti-flood pipeline existed. It saw the bomb after the bomb went off.\n\n## The error path of the bomb leaked a throttler slot.\n\nThe `if err != nil` after `b.Decompress` reads:\n\n```go\nif b.IsCompressed {\n err = b.Decompress(mdi.marshalizer)\n if err != nil {\n log.Error(\"MultiDataInterceptor.ProcessReceivedMessage\", \"err\", err.Error())\n return err\n }\n}\n```\n\nThe function returns. The throttler slot acquired by `preProcessMessage` is not released. The sibling error paths in the same function (the unmarshal failure, the empty-data check, the topic anti-flood failure, the per-originator whitelist check) all call `mdi.throttler.EndProcessing()` explicitly before returning. The decompression failure does not.\n\nThe throttler is the local goroutine pool. Production sizing is 100. A peer that ships 100 malformed compressed batches, each cheap to construct and each failing decompression, fills the throttler permanently. Subsequent legitimate batches arrive to a full pool and return `ErrSystemBusy` until the operator restarts.\n\nGitHub assigned this companion bug a separate identifier, GHSA-74m6-4hjp-7226. CVE-2026-44697 picked up the OOM primitive at GHSA-87m7-qffr-542v. The throttler-leak primitive does not have a CVE of its own. The same merge closed both.\n\n## The fix names the assumption out loud.\n\nThe merge that became v1.7.17 landed eight security commits in one push on 2026-05-11. The first, KLC-2352, added `MaxDecompressedBatchSize = 10 * 1024 * 1024` and threaded it through `decompressGzip` as an `io.LimitReader(reader, max+1)` cap, plus a cross-check that the inflated length equals `ba.DataSize`:\n\n```go\nif int64(len(result)) != int64(ba.DataSize) {\n return common.ErrDecompressedSizeMismatch\n}\n```\n\nThe second, KLC-2353, added `MaxItemsPerBatch = 8192` and checked it twice: once immediately after unmarshal (catches uncompressed item bombs) and once after decompress (catches compressed item bombs whose inflated payload fits under the 10 MiB cap). The third, KLC-2356, moved `throttler.CanProcess()` out of the `!isMessageFromSelfToSelf` branch so the local goroutine-capacity gate runs on every incoming message. Five more cleaned up panic recovers in `HdrInterceptorProcessor`, a `debugHandler` race exposed by `go test -race`, the absent `BlacklistPeer` call on malformed compressed batches, comma-ok guards on the transaction interceptor's type assertions, and a `shouldProcess := isWhiteListed || true` tautology in `SingleDataInterceptor` that had been quietly reducing one filter to a constant.\n\nThe KLC-2353 commit body carries the assumption the original code had been running on, transcribed and signed:\n\n> ProcessReceivedMessage is reachable only via the libp2p pubsub callback in networkMessenger.pubsubCallback, so the pubsub.DefaultMaxMessageSize (1 MiB) ceiling is always upstream and a duplicate cap at our layer would be dead code.\n\nThe wire bound is real. The maintainer is correct, today, that every path into `ProcessReceivedMessage` traverses libp2p pubsub. The bug is the rest of the sentence the original author did not write down: the 1 MiB bound is on the *wire*, not on the *inflated payload*. A 48 KiB gzip stream is a 48 KiB wire payload, and the bus's 1 MiB ceiling is satisfied. Decompression turns it into multiple gigabytes of heap. The 1 MiB ceiling caps the input to the gzip extractor. The gzip extractor's output was unbounded by anything in this codebase.\n\nThe comment names the upstream cap accurately and is silent about the function the gzip extractor applies between the upstream cap and the parser's working set. The fix is a 10 MiB explicit cap and a runtime check against the sender's own `DataSize` field. The sender's own `DataSize` field had been on the wire the whole time.\n\n## The 1 MiB was the medium's. The 10 MiB is the parser's.\n\nThis is the [Closed Network Assumed](/patterns/closed-network-assumed) pattern. A parser written for a \"trusted\" bus accepts framing fields as if the protocol's valid-range constraints were guaranteed by the medium. Sequence numbers, length fields, and indices arrive without bounds checks because the developer's threat model excludes adversaries on the wire. When the bus admits a malformed frame, the protocol-derived constant becomes the size of the overflow.\n\nKlever-Go is not OP-TEE J1939 reading a sequence number off a CAN frame, and it is not [BIRD's `as_path_match`](/posts/bird-cve-2026-49943-buffer-bound-is-an-operator-policy) allocating a 2048-entry stack array against an RFC 4271 wire cap that RFC 8654 quietly lifted a decade later. The medium is libp2p pubsub. The constraint the medium guarantees is `pubsub.DefaultMaxMessageSize = 1 MiB`. The transform that breaks the proportionality between the medium's bound and the parser's bound is gzip. The 1 MiB the bus enforces and the multiple gigabytes the parser allocates are connected by a function whose inverse lives in the gzip library, not in the framing.\n\nThe exhibits on this pattern share one move: a constant somewhere in the codebase was sized to fit a bound the medium enforced at the time the code was written, and the implementer wrote down the resulting number rather than the relationship that produced it. CZ.NIC published BIRD's closed-network assumption inside the CVE record when MITRE asked them to fix the bug. Klever-Go's maintainer published it inside the fix commit. Same worldview, two different artifacts of the moment the assumption broke.\n\nThe Klever-Go fix introduces `MaxDecompressedBatchSize` as an explicit constant inside `data/batch/batch.go`. The comment above the constant runs four lines and names libp2p, the per-peer antiflood budget, and the blacklist threshold. It is the same constant the previous file did not have, sized against the same considerations the previous author had implicitly used to decide they did not need one. The bound moved into the code.\n\n## What was not in the CVE description\n\nThe CVE record names `Batch.Decompress` and `MultiDataInterceptor`. The companion advisory GHSA-74m6-4hjp-7226 adds throttler-slot accounting. Neither names the seven non-decompression security commits the same merge landed: the panic-recover gap in `HdrInterceptorProcessor.Save`, the `debugHandler` race the worker goroutines were carrying past a released RLock, the `shouldProcess := isWhiteListed || true` tautology in `SingleDataInterceptor`, the missing `BlacklistPeer` call on malformed compressed batches that previously left a no-cost retry channel for the throttler-leak primitive, the comma-ok guards on the transaction-type assertions inside the interceptor goroutine body, the `mutHandlers.RLock` held across user callbacks that recursive-RLock self-deadlocked when a handler called `RegisterHandler`, and the `nil` propagation in `baseDataInterceptor.processInterceptedData` that had been reusing a stale loop-variable error on the Save success path.\n\nThe CVE captures the most legible bug in the interceptor pipeline. It does not capture the audit that found it.\n\nPoC: [klever-io/klever-go @ 333f6ec](https://github.com/klever-io/klever-go/commit/333f6ec910906e227705fc5767dc897d8fbfc862)","closing_line":"The bound was in libp2p. The bound was in `DataSize`. The bound was not in `decompressGzip`.","hook_md":"The vulnerable line is `data/batch/batch.go:43` in Klever-Go v1.7.16. It reads `result, err := io.ReadAll(reader)`, where `reader` is a `*gzip.Reader` wrapping bytes a libp2p pubsub peer just sent. There is no `io.LimitReader`. There is no size argument. There is no reference to the `DataSize` field the same protobuf message carries on the wire alongside the gzip stream.\n\nFour functions up the same file, the Batch sender writes that field on every outbound batch as `ba.DataSize = int32(len(data))`, where `len(data)` is the size of the marshaled payload before compression. The protocol declares the decompressed size of every batch in field 5 of the wire format. The decoder in v1.7.16 never read its own field.","post_id":573,"slug":"klever-go-cve-2026-44697-decoder-did-not-read-its-own-field","title":"CVE-2026-44697: Klever-Go's Batch Compress() Wrote The Decompressed Size On The Wire. Decompress() Did Not Read It.","type":"initial","unreadable_sentence":"The sender wrote the decompressed size onto the wire. The decoder did not read its own field."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCarK+XgAKCRDeZjl4jgkQ Jof9AP9h5q6VbpJnE27Ug+OUt7W6LVRFNIFFA5aL8SdpKT/RlAD8De8aBqsQUVil J8HpxFPEi23Dr87vWXIRVZJElYnCkgs= =n20d -----END PGP SIGNATURE-----