consensus: Add CompactSize range check to deserialization#5697
consensus: Add CompactSize range check to deserialization#5697apoelstra merged 1 commit intorust-bitcoin:masterfrom
Conversation
Reject CompactSize values exceeding MAX_COMPACT_SIZE (0x02000000) during deserialization, matching Bitcoin Core's serialize.h limit. Extract read_compact_size logic into a private free function to allow tests to bypass the range check when validating non-minimal encoding. Add test for the new SizeTooLargeCompactSize error at the boundary. Update bip152 error test to expect failure at deserialization rather than at index computation, since the range check now triggers earlier.
3f3f5ec to
1dd1d92
Compare
|
Thanks man! Good work on the fuzzing. A couple of comments/questions for the project more than just for you.
|
More context: I found this while doing differential fuzzing in the PSBT parser. Bitcoin Core always checks if the |
|
Ha! Interesting timing then. I only recently raised this issue: #5622 which is around the key type and its usage of a CompactSize encoding. Note in the associated PR the code comment 'the protocol abuses ...' (which I suggested). Amusing that its not the only bug we have on this data field and I"m now not surprised we missed it. |
we previously had this was discussed here: #5057 (comment) |
|
Ouch so I removed it. Thanks @jrakibi! |
Yes, adding the rust-psbt is already on the plan. I'll check to see if it gets done this week and report any issues I find. |
|
Boss! |
|
I'm gonna go ahead and ACK/merge this. But
|
|
I created rust-bitcoin/rust-psbt#74 to track it over in |
No, We can do fuzzing in any commit/branch.
Yes, I've tested with rust-psbt and it has the same issue as rust-bitcoin. Since rust-psbt v0 uses the |
Manually backport rust-bitcoin#5697. On `master` the `VarInt` type is gone but the deserialization bug fixed by 5697 exists here none the less. Add the same range check to `Decodable for VarInt`.
|
Backported in #5921 |
Reject
CompactSizevalues exceedingMAX_COMPACT_SIZE(0x02000000) during deserialization, matching Bitcoin Core's serialize.h limit.Extract read_compact_size logic into a private free function to allow tests to bypass the range check when validating non-minimal encoding.
Add test for the new
OversizedCompactSizeerror at the boundary.Update bip152 error test to expect failure at deserialization rather than at index computation, since the range check now triggers earlier.
Found by differential fuzzing using bitcoinfuzz.