Skip to content

Commit d483c29

Browse files
committed
dir/gen3: check for magic when parsing CPD
Signed-off-by: Daniel Maslowski <[email protected]>
1 parent 0394c66 commit d483c29

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/dir/gen3.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ impl CodePartitionDirectory {
150150
let Ok((header, _)) = CPDHeader::read_from_prefix(data) else {
151151
return Err("could not parse CPD header".to_string());
152152
};
153+
154+
let m = header.magic;
155+
if m != CPD_MAGIC_BYTES {
156+
return Err(format!(
157+
"missing CPD magic; got {m:02x?}, wanted {CPD_MAGIC_BYTES:02x?}"
158+
));
159+
}
160+
153161
let name = header.name();
154162
let header_size = if header.version_or_checksum == 0x00140102 {
155163
HEADER_SIZE + 4

0 commit comments

Comments
 (0)