Repository navigation
Bound the exceptional bits read to the validated length - #163
Merged
Merged
Conversation
m_exceptional_bits is sized from num_exceptional_bits, but UnpackInt5Array was given the whole remainder of the input as its source range. That function is bounded by the source, not the destination, so any input longer than the fingerprint needs writes past the end of the vector. The length check above it only establishes a lower bound on the input size, which does not help here. Pass the end iterator at the length that check validated. Trailing data is then ignored, which is what the surrounding code already assumes.
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughChangesFingerprint decompression
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
m_exceptional_bitsis sized fromnum_exceptional_bits, butUnpackInt5Arraywas given the whole remainder of the input as its source range:m_exceptional_bits.resize(GetUnpackedInt5ArraySize(GetPackedInt5ArraySize(num_exceptional_bits))); UnpackInt5Array(input.begin() + offset, input.end(), m_exceptional_bits.begin());UnpackInt5Arraywrites one output byte per 5 input bits and stops when the source runs out, so the number of writes follows the input length rather than the size of the destination. Any input longer than the fingerprint actually needs therefore writes past the end of the vector.The check just above only establishes a lower bound:
if (input.size() < offset + GetPackedInt5ArraySize(num_exceptional_bits)) {so it does not constrain this.
The fix passes the end iterator at the length that check already validated. Trailing data is then ignored, which is what the surrounding code assumes anyway —
m_bitsis truncated to the number of values the header declares, and everything after the exceptional bits was already unused.UnpackInt3Arraya few lines earlier is not affected: there the destination is sized from the same input length that drives the loop, so the two agree.Testing
Added
OneItemOneBitExceptWithTrailingData— the existingOneItemOneBitExceptcase with four trailing bytes, asserting it still decodes to the same value.On master that test aborts in a
Debugbuild with a past-the-end iterator from the libstdc++ debug checks. With the fix, the full suite passes (98 tests,-DFFT_LIB=kissfft -DCMAKE_BUILD_TYPE=Debug).