Fix color correction flaw introduced in 0.6.0 #136
Merged
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.
When we added the split symbol/color decode and the motivating color correction logic, that included a potential issue where said logic might get confused by the very specific case of the final "normal" block of the fountain encode.
As a refresher: wirehair encodes the initial file verbatim as its initial N blocks -- only after exhausting these initial file bytes does it begin its (almost magical) GF256-inspired permutations. Each block up to the final of these initial N will be exactly the expected block size, and each of the successive ones will also match exactly. But the one at the tail end, provided the block size and file size do not divide perfectly (which will be the normal case), will be smaller. We want all the blocks to exactly match, so the encoder skips that one. (example: block size 22, file size 100. After the 0th through 3rd blocks, we'll have 12 bytes remaining, meaning block_id=4 will be smaller than expected. So the next block we'll send will be block_id=5)
The color correction logic exploits the presence of a deterministic header -- which contains the block_id as its trailing 2 bytes. We can do one of the following:
We're now doing option (3).
Follow up to #134, #135, and #91.
I'm not sure how frequent this problem was in the wild, but it would've manifested only for very small files.