Skip to content

Commit 686aa28

Browse files
authored
Merge pull request #89 from tweedegolf/extra-crc-collision-check
Add extra check to catch crc collisions
2 parents 6dfe57b + 223f15e commit 686aa28

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Added `Key` implementation for the unit type `()` for easy storage of a single value
88
- *Breaking:* Changed API for map `fetch_all_items` such that the `Key` is captured in `MapItemIter`.
99
- Fixed some logic so queue can be used on a single page. (It's still recommended to use at least 2 pages for both the queue and the map)
10+
- Add some extra logic to catch more crc collisions
1011

1112
## 4.0.3 18-06-25
1213

src/item.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,27 @@ impl ItemHeader {
9797
break;
9898
}
9999

100-
Ok(Some(Self {
100+
let header = Self {
101101
length: u16::from_le_bytes(header_slice[Self::LENGTH_FIELD].try_into().unwrap()),
102102
crc: {
103103
match u32::from_le_bytes(header_slice[Self::DATA_CRC_FIELD].try_into().unwrap()) {
104104
0 => None,
105105
value => Some(NonZeroU32::new(value).unwrap()),
106106
}
107107
},
108-
}))
108+
};
109+
110+
if header.next_item_address::<S>(address) > end_address {
111+
// We have a header here that's claims it's larger than is possible
112+
// This is never written. So either it's a bug or there's a CRC collision
113+
// Let's assume the latter
114+
return Err(Error::Corrupted {
115+
#[cfg(feature = "_test")]
116+
backtrace: std::backtrace::Backtrace::capture(),
117+
});
118+
}
119+
120+
Ok(Some(header))
109121
}
110122

111123
pub async fn read_item<'d, S: NorFlash>(

0 commit comments

Comments
 (0)