Skip to content

GHSA-pj89-8hch-p7vp

CVE Information

Impact

When cbor_stream_decode() returns CBOR_DECODER_NEDATA, it reports in required the total number of bytes that must be available before decoding can make progress. This total is computed with a size_t addition that wraps around for very large declared lengths, so required can be smaller than, or equal to, the number of bytes already provided:

  • On all platforms, a byte string or text string with an 8-byte length close to UINT64_MAX (for example 5B FF FF FF FF FF FF FF FF) reports required = 8 after 9 bytes were provided.
  • On platforms with a 32-bit size_t, 4-byte lengths close to UINT32_MAX also wrap (for example 5A FF FF FF FF reports required = 4 after 5 bytes were provided).

The documentation tells callers to accumulate at least required bytes and then retry. A client that does this without other limits retries immediately with the same input and never terminates, so a single crafted input causes a denial of service. Clients that use required to size buffers receive a wrong value. libcbor itself does not access memory out of bounds.

Not affected:

  • cbor_load() and the other item-based APIs, which return CBOR_ERR_NOTENOUGHDATA without retrying.
  • Clients that do not use required.

The issue was introduced in 0.8.0 (commit cd36861), when required changed to report the total number of bytes needed.

Patches

Fixed in 0.14.1. Upgrade to 0.14.1 or later.

The fix is commit 07b908b in 0.14.1 and commit b965ec2 on master, where it will be part of the next minor release. One change fixes both this advisory and GHSA-frh9-3gqx-pqg2, which share the root cause in claim_bytes.

required is now computed without overflow and saturates at SIZE_MAX when the total does not fit into size_t, which marks a claim that the address space can never satisfy. Clients should still cap how much data they are willing to buffer.

Verified on a 32-bit (i386) build: the added regression tests fail against 0.14.0 and pass with the fix, with no other test affected.

A CVE ID has been requested and will be added to this advisory once assigned.

Workarounds

After CBOR_DECODER_NEDATA, treat a required value that is not greater than the number of bytes passed to cbor_stream_decode() as an error. A correct required is always greater than that. Also cap required at the largest message size your application accepts.