Trailing characters on zero values are accepted
- Dominant language
- Rust
- Stars
- 225
- Forks
- 70
- Avg merge
- 16h 54m
- Merged PRs (30d)
- 8
Description
**Version**
```
1.12.3
```
**Platform**
```
Darwin Dans-MacBook-Pro-4.local 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000 arm64
```
**Description**
I was noticing that reth was succeeding when it got `eth_getStorageAt` calls that had a 67-character "zero" slot:
`0x00000000000000000000000000000000000000000000000000000000000000000`
I wrote a crude test to check this:
```rust
#[test]
fn test_serde_invalid_size_error_zero() {
// Test that if we add a character to a zero value for the given number of bits, we get an
// error.
const_for!(BITS in SIZES {
const LIMBS: usize = nlimbs(BITS);
// repeated pattern of 0
let mut zero_bytes = BITS / 8;
if BITS % 8 != 0 {
zero_bytes += 1;
}
let mut serialized = String::from("\"0x");
// push zero bytes
for _ in 0..zero_bytes {
serialized.push('0');
serialized.push('0');
}
// add one zero
serialized.push('0');
// edge case: zero bits, we should only be able to deser `0x0` for the zero bit Uint
if BITS == 0 {
serialized.push('0');
}
serialized.push('\"');
// ensure format of serialized value is correct ("0x...")
assert_eq!(&serialized[..3], "\"0x");
// last character should be a quote
assert_eq!(&serialized[serialized.len() - 1..], "\"");
let deserialized = serde_json::from_str::>(&serialized);
assert!(deserialized.is_err(), "{BITS} {serialized}");
});
}
```
To be compliant with QUANTITY, these should be rejected.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.