mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-20 19:57:45 +00:00
Add invalid data test for Lgb, add a simple check for invalid data
This commit is contained in:
parent
f460f5b944
commit
170a1d27a7
1 changed files with 24 additions and 2 deletions
22
src/lgb.rs
22
src/lgb.rs
|
@ -485,6 +485,9 @@ impl Layer {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
|
|
||||||
let file_header = LgbHeader::read(&mut cursor).unwrap();
|
let file_header = LgbHeader::read(&mut cursor).unwrap();
|
||||||
|
if file_header.file_size < 0 || file_header.total_chunk_count < 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let chunk_header = LayerChunk::read(&mut cursor).unwrap();
|
let chunk_header = LayerChunk::read(&mut cursor).unwrap();
|
||||||
|
|
||||||
|
@ -525,3 +528,22 @@ impl Layer {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::fs::read;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_invalid() {
|
||||||
|
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
|
d.push("resources/tests");
|
||||||
|
d.push("random");
|
||||||
|
|
||||||
|
// Feeding it invalid data should not panic
|
||||||
|
Layer::from_existing(&read(d).unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue