mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 18:54:05 +02:00
verify lump size before reading
This commit is contained in:
parent
9398ea7cf5
commit
65af835320
2 changed files with 11 additions and 0 deletions
|
|
@ -9,6 +9,11 @@ pub enum BspError {
|
||||||
UnexpectedHeader(Header),
|
UnexpectedHeader(Header),
|
||||||
#[error("bsp lump is out of bounds of the bsp file")]
|
#[error("bsp lump is out of bounds of the bsp file")]
|
||||||
LumpOutOfBounds(LumpEntry),
|
LumpOutOfBounds(LumpEntry),
|
||||||
|
#[error("Invalid lump size, lump size {lump_size} is not a multiple of the element size {element_size}")]
|
||||||
|
InvalidLumpSize {
|
||||||
|
element_size: usize,
|
||||||
|
lump_size: usize,
|
||||||
|
},
|
||||||
#[error("unexpected length of uncompressed lump, got {got} but expected {expected}")]
|
#[error("unexpected length of uncompressed lump, got {got} but expected {expected}")]
|
||||||
UnexpectedUncompressedLumpSize { got: u32, expected: u32 },
|
UnexpectedUncompressedLumpSize { got: u32, expected: u32 },
|
||||||
#[error("error while decompressing lump")]
|
#[error("error while decompressing lump")]
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,12 @@ impl<R: BinReaderExt + Read> LumpReader<R> {
|
||||||
where
|
where
|
||||||
F: FnMut(&mut LumpReader<R>) -> BspResult<T>,
|
F: FnMut(&mut LumpReader<R>) -> BspResult<T>,
|
||||||
{
|
{
|
||||||
|
if self.length % size_of::<T>() != 0 {
|
||||||
|
return Err(BspError::InvalidLumpSize {
|
||||||
|
element_size: size_of::<T>(),
|
||||||
|
lump_size: self.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
let num_entries = self.length / size_of::<T>();
|
let num_entries = self.length / size_of::<T>();
|
||||||
let mut entries = Vec::with_capacity(num_entries);
|
let mut entries = Vec::with_capacity(num_entries);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue