fix(binarycodec): verify IOU not-XRP bit before sign parsing#311
Open
e-desouza wants to merge 1 commit into
Open
fix(binarycodec): verify IOU not-XRP bit before sign parsing#311e-desouza wants to merge 1 commit into
e-desouza wants to merge 1 commit into
Conversation
Add a guard in `_deserialize_issued_currency_amount` that rejects any 8-byte IOU value buffer where byte 0 has the 0x80 "not XRP" bit clear. Without the check a malformed buffer reaching the IOU branch could produce a sign-inverted result because the sign bit (0x40) would be read against an unexpected bit pattern. Adds four unit tests: positive IOU round-trip, negative IOU round-trip with sign preservation, and two rejection tests confirming that buffers with 0x80 missing return an error. Closes #260.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #311 +/- ##
=======================================
Coverage ? 84.27%
=======================================
Files ? 200
Lines ? 20802
Branches ? 0
=======================================
Hits ? 17531
Misses ? 3271
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Why
The IOU amount deserialization function (
_deserialize_issued_currency_amount) reads the sign from bit 6 of byte 0 (the0x40mask) but did not first verify that byte 0 has the0x80"not XRP" bit set, which is required by the XRPL IOU wire format. A malformed 8-byte buffer where0x80is absent but the buffer still reaches the IOU branch — because it is neither native (0x80clear,0x20clear is native) nor MPT (0x20set) — could trigger incorrect sign parsing. The routing invariant that currently prevents this from occurring in theAmount::serializepath is not enforced at the deserialization layer itself, leaving a gap if the routing logic is ever extended or the function is called directly.Closes #260.
What changed
src/core/binarycodec/types/amount.rs: added an early guard at the top of_deserialize_issued_currency_amountthat returnsInvalidReadFromBytesValuewhenbytes[0] & 0x80 == 0. The guard uses the existing_NOT_XRP_BIT_MASKconstant and the same error variant already used throughout the binary codec.test_iou_positive_sign_round_trips— a valid positive IOU (byte 0 =0xC0) serializes without error.test_iou_negative_sign_round_trips— a valid negative IOU (byte 0 =0x80, sign bit clear) serializes with a negative value string.test_iou_missing_not_xrp_bit_returns_error— bytes with0x80absent return an error from_deserialize_issued_currency_amount.test_iou_all_zero_bytes_returns_error— all-zero bytes (also lacking0x80) are rejected.How to validate
All tests pass and clippy reports zero warnings.