1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-20 11:47:46 +00:00

Add invalid data test for Lgb, add a simple check for invalid data

This commit is contained in:
Joshua Goins 2024-04-16 21:57:30 -04:00
parent f460f5b944
commit 170a1d27a7

View file

@ -485,9 +485,12 @@ 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();
let old_pos = cursor.position(); let old_pos = cursor.position();
let mut layer_offsets = vec![0i32; chunk_header.layer_count as usize]; let mut layer_offsets = vec![0i32; chunk_header.layer_count as usize];
@ -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());
}
}