Repository navigation
Fix review findings and make the fountain decoder allocation-free - #17
Merged
Merged
Conversation
Every fragment was already held, so no later part re-triggered the join and the scan never completed.
prng_next_int() returns max + 1 when prng_next_double() rounds to 1.0, which read one element past the remaining-index list.
CPython sets LC_CTYPE from the environment, where islower() and tolower() also accept Latin-1 letters.
ur_attr never fell through to locals_dict, so the GC found no finaliser and every UR object leaked its native copy.
A MemoryError, or the UnicodeError a non-UTF-8 bip39 word raises, long-jumped past the free.
…ts by number Mixed frames were allocation-bound: each copied every recovered fragment and stored equation it was checked against.
Frames with an embedded NUL or lone surrogate are rejected instead of truncated or raised, MicroPython UR types must be NUL-free str, empty payloads get a real buffer, the CPython FountainEncoder view joins cyclic GC, first_seq_num stops at 2^32 - 2, and the unix port builds under -Werror=float-conversion.
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.
Summary
Fixes from a review of cUR, plus a rework of the multipart decoder that makes lossy scans of large URs 11–13× faster on ESP32-P4. Each fix is its own commit and does not depend on the rework.
Performance
Mixed frames were allocation-bound: each one copied every recovered fragment and stored equation it was checked against. Equations are now reduced in place, recovered fragments are indexed by fragment number, and each frame is parsed with a single allocation.
Decoder time on an ESP32-P4 (360 MHz, PSRAM 200 MHz):
The two perf commits do not change decoding: after every frame the decoder state matches the preceding commit, across 1,900 randomized scans and 300,000 mutated frames.
Fixes
seq_num0 and inconsistent fragment sizes are rejected.*; indexes above 32 bits were truncated.URobjects never freed their memory.FountainEncoderviews could form uncollectable cycles.first_seq_num = 2^32−1failed only at the first part.Stricter parsing now rejects input that used to be accepted: hd-keys without a chain code, repeated CBOR keys, trailing bytes and malformed sequence components.