Skip to content

Commit cb88531

Browse files
committed
adding better size assertions
1 parent bc77404 commit cb88531

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ext2/src/dir.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@ impl DirEntry {
175175
}
176176

177177
fn from(dir_entries_have_type: bool, value: &[u8]) -> Self {
178+
let required_size = Self::size(0);
178179
debug_assert!(
179-
value.len() >= 8,
180-
"need at least 8 byte, but got {}",
180+
value.len() >= required_size as usize,
181+
"need at least {required_size} byte, but got {}",
181182
value.len()
182183
);
183184

@@ -194,6 +195,10 @@ impl DirEntry {
194195
} else {
195196
None
196197
};
198+
199+
let required_size = Self::size(name_length); // now that we have the name length, we can compute the actual required size
200+
debug_assert!(value.len() >= Self::size(name_length) as usize, "need at least {} byte, but have only {}", required_size, value.len());
201+
197202
let name_bytes = value[8..8 + name_length as usize].to_vec();
198203
Self {
199204
inode: InodeAddress::new(arr.inode).unwrap(),

0 commit comments

Comments
 (0)