mirror of
https://github.com/storytold/craft-anything.git
synced 2026-11-05 20:47:45 +01:00
b9ca099903
Replays #688 and #690–#715. DEX, Java, SQLite, Android, ZIP, ASAR, file system, PyInstaller, JSON config and packet parsers keep to their declared lengths and refuse impossible values. Co-authored-by: Afloat <132809511+Afloat16@users.noreply.github.com>
30 lines
1.4 KiB
Rust
30 lines
1.4 KiB
Rust
use craft_anything_formats::fsread::{self, Limits};
|
|
|
|
const FILE_INODE: usize = 5120 + 10 * 128;
|
|
|
|
#[test]
|
|
fn a_nonzero_pointer_outside_the_image_is_missing_data_not_a_sparse_hole() {
|
|
for extents in [false, true] {
|
|
let mut data = craft_anything_testkit::firmware::ext_image(extents);
|
|
let pointer = FILE_INODE + if extents { 60 } else { 40 };
|
|
data[pointer..pointer + 4].copy_from_slice(&u32::MAX.to_le_bytes());
|
|
let image = fsread::extfs::read(&data, &Limits::default());
|
|
let hello = image.entries.iter().find(|e| e.path == "hello.txt").unwrap();
|
|
assert_eq!(hello.size, 22);
|
|
assert!(hello.data.is_none(), "extent mode {extents}");
|
|
assert!(!image.complete);
|
|
assert!(image.warnings.iter().any(|w| w.contains("block")));
|
|
assert_eq!(image.entries.iter().find(|e| e.path == "sub/note").unwrap().data.as_deref(), Some(b"nested note".as_slice()));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_true_zero_pointer_still_represents_a_sparse_hole() {
|
|
let mut data = craft_anything_testkit::firmware::ext_image(false);
|
|
data[FILE_INODE + 40..FILE_INODE + 44].fill(0);
|
|
let image = fsread::extfs::read(&data, &Limits::default());
|
|
let hello = image.entries.iter().find(|e| e.path == "hello.txt").unwrap();
|
|
assert_eq!(hello.data.as_deref(), Some([0u8; 22].as_slice()));
|
|
assert!(image.complete, "{:?}", image.warnings);
|
|
}
|