1
0
Fork 0
mirror of https://codeberg.org/icewind/vbsp.git synced 2026-06-04 11:04:07 +02:00

validate internal references on parse

This commit is contained in:
Robin Appelman 2022-02-21 19:27:01 +01:00
commit db738c5eb3
6 changed files with 157 additions and 40 deletions

View file

@ -22,6 +22,8 @@ pub enum BspError {
String(#[from] StringError),
#[error("Malformed field found while parsing: {0:#}")]
MalformedData(binrw::Error),
#[error("bsp file is well-formed but contains invalid data")]
Validation(#[from] ValidationError),
}
impl From<binrw::Error> for BspError {
@ -61,3 +63,16 @@ pub enum StringError {
#[error("String is not null-terminated")]
NotNullTerminated,
}
#[derive(Debug, Error)]
pub enum ValidationError {
#[error(
"A {source_} indexes into {target} but the index {index} is out of range of the size {size}"
)]
ReferenceOutOfRange {
source_: &'static str,
target: &'static str,
index: i64,
size: usize,
},
}