mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-06 01:54:51 +01:00
io/region: avoid panic for invalid chunk lengths
This commit is contained in:
parent
da8ac506d9
commit
7c7e36f6be
1 changed files with 7 additions and 3 deletions
|
@ -26,12 +26,12 @@ fn parse_header(header: &ChunkArray<u32>) -> HashMap<u32, ChunkDesc> {
|
||||||
let offset_len = u32::from_be(chunk);
|
let offset_len = u32::from_be(chunk);
|
||||||
|
|
||||||
let offset = offset_len >> 8;
|
let offset = offset_len >> 8;
|
||||||
if offset == 0 {
|
let len = offset_len as u8;
|
||||||
|
|
||||||
|
if offset == 0 || len == 0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let len = offset_len as u8;
|
|
||||||
|
|
||||||
map.insert(offset, ChunkDesc { coords, len });
|
map.insert(offset, ChunkDesc { coords, len });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,11 @@ where
|
||||||
.context("Failed to decode chunk size")?,
|
.context("Failed to decode chunk size")?,
|
||||||
) as usize;
|
) as usize;
|
||||||
|
|
||||||
|
if len < 1 || len > buf.len() {
|
||||||
|
bail!("Invalid chunk size");
|
||||||
|
}
|
||||||
let buf = &buf[..len];
|
let buf = &buf[..len];
|
||||||
|
|
||||||
let (format, buf) = buf.split_at(1);
|
let (format, buf) = buf.split_at(1);
|
||||||
if !matches!(format, [2]) {
|
if !matches!(format, [2]) {
|
||||||
bail!("Unknown chunk format");
|
bail!("Unknown chunk format");
|
||||||
|
|
Loading…
Add table
Reference in a new issue