Repository navigation
Fix Audit findings - #22
Merged
Merged
Conversation
A from_data_item() that had built its value leaked it when the registry wrapper could not be allocated (bytes, psbt, bip39, keypath, output), and output_to_data_item() leaked the item it was wrapping when a script expression tag could not be. A bip39 language that could not be copied was dropped; it now fails the decode. test_ur_alloc numbers every allocation (malloc, calloc, realloc) and fails each in turn across descriptor encode, the simple types and a lossy multi-part session, checking each run for leaks and for wrong results.
cbor_map_get_int() built its lookup key on the heap, so an allocation failure read as "key absent". Optional fields were then dropped instead of failing the decode: a testnet key rendered as an xpub, an origin path or a bip39 language went missing, under a valid checksum. The key is now on the stack. test_ur_alloc also fails every allocation while decoding a crypto-output and a crypto-account, and checks the bip39 language.
…ath length - keypath_to_data_item() left out the required components array when it was empty, so [fingerprint]xpub encoded to a crypto-output this library's own decoder rejected. The array is now always written. - An origin that is only a source fingerprint renders as [fingerprint] instead of being dropped. - keypath_new() refuses more than 255 components (KEYPATH_MAX_COMPONENTS): the path length is the BIP32 depth byte, which wrapped for longer paths.
Descriptor text the parser did not understand was skipped, so a malformed descriptor encoded as a different one. It is now an error: - a path component must be an index or '*' followed by '/' or the end: 0'5, 0*, a//b and a trailing '/' are rejected - an origin is a fingerprint alone or a fingerprint, '/' and a path - a '#checksum' is verified instead of discarded - one ')' closes each expression and nothing follows the last - multi() needs a comma after the threshold and none after the last key - key text longer than an xpub is refused before base58 decoding, which is quadratic Script expressions must nest as an optional sh, an optional wsh, then one key expression, both in descriptor text and in CBOR tags: multi(wpkh(k)), wpkh(pkh(k)), wsh(wpkh(k)) and addr(k) are rejected.
They were stored NUL-terminated and so truncated at the first NUL, which let this decoder and others disagree about the same payload.
The UR type was taken from the first frame before its body was checked, so one misread or stray frame of another type made every later frame fail with INVALID_TYPE. The type is now established together with the rest of the message header, by a frame that passed every check. An over-size frame is terminal only when it starts a message. Once one is in progress it cannot belong to it, and is rejected with INVALID_PART like any other foreign frame instead of ending the scan.
ur_encoder_new() built streams of more than UR_MAX_SEQ_LEN parts, or multi-part messages over UR_MAX_MESSAGE_LEN, that this library's own decoder then rejected as UNSUPPORTED_SIZE. It now returns NULL for them, and ur_encoder_within_limits() lets callers tell that case from an allocation failure; both bindings raise ValueError for it. Single-part messages are not reassembled and keep no size limit.
…ection buffer - part_indexes_t holds part_index_t (uint16_t) entries instead of size_t. A mixed part of a long message carries more index bytes than payload (about 137 entries at 1000 fragments), so this is most of the decoder's working memory: a quarter of it on 64-bit targets, half on 32-bit. Fragment selection is unchanged. - The fountain layer accepts at most FOUNTAIN_MAX_SEQ_LEN (65536) fragments, in both directions, so every fragment number fits. - The encoder keeps a selection work buffer instead of allocating one for every fountain part, as the decoder already did. - choose_fragments() without a cached sampler fails when the sampler cannot be allocated. It used to fall back to degree 1, which selects different fragments from the sender's.
…build option - A mixed part dropped because the table was full, or its entry could not be allocated, was still recorded as seen, so an animation looping over a fixed set of frames could never offer it again. A part is now recorded only once it has been used. - The limit on stored mixed parts is UR_MAX_MIXED_PARTS, overridable at compile time. The default stays 256. - The weighted progress estimate keeps its scratch array with the decoder instead of allocating one on every call.
The getter made str and bytes objects from the result only to pass them to the UR constructor, which copied the payload again. It now fills a UR directly, as the CPython binding does.
test_ur_fuzz feeds mutated CBOR payloads and descriptor text through the type codecs, and multi-part streams through a channel that loses, repeats, delays and injects hostile CRC-valid frames. It checks that whatever is accepted round-trips, that a clean stream always decodes to the message that was encoded, and that the decoder's state machine holds after every part. CI now also runs make DEBUG=1 test, so every suite goes through ASan and UBSan.
…rule - README: the UR_MAX_* limits including UR_MAX_MIXED_PARTS, UNSUPPORTED_SIZE among the terminal states, the encoder honouring the decoder's limits, strict descriptor text, and why an xpub without its origin comes back as different text. A test pins that the key itself survives. - The first well-formed frame fixes the message, so callers should restart a decoder that only reports errors. - bytewords_decode_raw() does verify the CRC32; its comment said otherwise.
The two-byte payload was shorter than min_fragment_len, so ur_encoder_new() returned NULL and the app could never reach its PASS line on a board. The build was the only thing checked.
odudex
force-pushed
the
fix/audit-findings
branch
from
November 11, 2026 19:55
9eaea2f to
22f484f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fable 5.2 hardening and performance audit