reject CBOR array/map length equal to the indefinite-length marker#5274
reject CBOR array/map length equal to the indefinite-length marker#5274Angadi56 wants to merge 2 commits into
Conversation
Signed-off-by: Angadi Yashaswini <angadi@digiscrypt.com>
|
Nice, narrowly-scoped fix — the mechanics check out ( Consider reusing
Minor: Neither point blocks this fix; both would just make it more thorough/consistent with existing conventions in the same file. Generated by Claude Code |
Signed-off-by: Angadi Yashaswini <angadi@digiscrypt.com>
|
Both done. I swapped in The context string is now "size" and the expected messages in the tests are updated to match. Since the truncation half only manifests on 32-bit builds, I put the |
|
Thanks a lot! |
CBOR arrays and maps can prefix their element count with a full eight-byte integer, and the reader tells a definite-length container from an indefinite one by comparing that count against
detail::unknown_size(), which isSIZE_MAX. Nothing stops a definite count from being exactlySIZE_MAX, so on a 64-bit build a stream that declares0xFFFFFFFFFFFFFFFFelements narrows straight onto the sentinel andget_cbor_array/get_cbor_objectread the container as indefinite rather than rejecting it. The effect is that bytes like9B FF FF FF FF FF FF FF FF 01 02 FFcome back as[1, 2], read up to the next0xFFbreak, even though the neighboring count0xFFFFFFFFFFFFFFFEis correctly turned away as excessive. I noticed the gap while checking how the eight-byte length path lines up with the indefinite marker. The fix adds a smallget_cbor_container_sizehelper that narrows the length and rejects the one value that aliases the sentinel; such a count is larger than any container'smax_size()anyway, so no representable input changes behavior. The four-byte and eight-byte array and map cases route through it, and the indefinite forms stay as they were.make amalgamate.