1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-24 05:27:45 +00:00

Add invalid data test for Texture

This commit is contained in:
Joshua Goins 2024-04-16 22:08:22 -04:00
parent 17ba7f2389
commit 4b6166f8d0

View file

@ -82,7 +82,7 @@ impl Texture {
/// Reads an existing TEX file /// Reads an existing TEX file
pub fn from_existing(buffer: ByteSpan) -> Option<Texture> { pub fn from_existing(buffer: ByteSpan) -> Option<Texture> {
let mut cursor = Cursor::new(buffer); let mut cursor = Cursor::new(buffer);
let header = TexHeader::read(&mut cursor).unwrap(); let header = TexHeader::read(&mut cursor).ok()?;
// TODO: Adapted from Lumina, but this really can be written better... // TODO: Adapted from Lumina, but this really can be written better...
let mut texture_data_size = vec![0; min(13, header.mip_levels as usize)]; let mut texture_data_size = vec![0; min(13, header.mip_levels as usize)];
@ -141,3 +141,21 @@ impl Texture {
}) })
} }
} }
#[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
Texture::from_existing(&read(d).unwrap());
}
}