Keep RAW fixtures valid under shared container and strip bounds

This commit is contained in:
Dylan M. Taylor committed 2026-11-15 19:09:00 +00:00
1 parent 43cb606cea
commit 6bd59dbb43
4 files changed
+9 -10

No files matched your search

+3 -3
View File
@@ -105,10 +105,10 @@ fn cr3_file(coding: &[u8], sample: &[u8]) -> Vec<u8> {
let trak = box_bytes(b"trak", &box_bytes(b"mdia", &box_bytes(b"minf", &box_bytes(b"stbl", &tables))));
let mut file = box_bytes(b"ftyp", b"crx \0\0\0\x01crx isom");
file.extend(box_bytes(b"moov", &trak));
let offset = file.len();
file.extend_from_slice(sample);
let at = file.len() - sample.len() - 8; // the co64 offset field ends the moov
let at = file.len() - 8; // the co64 offset field ends the moov
let offset = file.len() + 8; // samples belong to the mdat payload, after its header
file[at..at + 8].copy_from_slice(&u64::try_from(offset).unwrap().to_be_bytes());
file.extend(box_bytes(b"mdat", sample));
file
}
+2 -3
View File
@@ -410,11 +410,10 @@ fn cr3_file(entry: &[u8], sample: &[u8]) -> Vec<u8> {
// The track length does not depend on the offset value (always a 64-bit field), so it can be
// measured with a placeholder before the real offset is known.
let track_len = track_box(entry, 0, sample.len() as u32).len();
let offset = (ftyp.len() + 8 + track_len + 7) & !7;
let offset = ftyp.len() + 8 + track_len + 8; // moov and mdat headers
let mut file = ftyp;
file.extend(box_bytes(b"moov", &track_box(entry, offset as u64, sample.len() as u32)));
file.resize(offset, 0);
file.extend_from_slice(sample);
file.extend(box_bytes(b"mdat", sample));
file
}
+2 -1
View File
@@ -1016,7 +1016,8 @@ fn malformed_semantic_masks_are_skipped() {
assert_eq!(decode(&bytes).unwrap().cpp, 3);
let masks = lightcraft_raw::semantic_masks(&bytes);
let names: Vec<&str> = masks.iter().map(|m| m.name.as_str()).collect();
assert_eq!(names, ["short strip", "sub area too small"]);
// Truncated strip pixels are rejected by the shared reader instead of zero-filled.
assert_eq!(names, ["sub area too small"]);
assert!(masks.iter().all(|m| m.sub_area.is_none()), "sub areas the mask doesn't fit are ignored");
for m in &masks {
let d = m.developed(Rect::new(0, 0, 8, 6), Rect::new(0, 0, 8, 6)).unwrap();
+2 -3
View File
@@ -231,11 +231,10 @@ mod cr3 {
let entry = box_bytes(b"CRAW", &craw);
let ftyp = box_bytes(b"ftyp", b"crx \0\0\0\x01crx isom");
let track_len = track(&entry, 0, sample.len() as u32).len();
let offset = (ftyp.len() + 8 + track_len + 7) & !7;
let offset = ftyp.len() + 8 + track_len + 8; // moov and mdat headers
let mut out = ftyp;
out.extend(box_bytes(b"moov", &track(&entry, offset as u64, sample.len() as u32)));
out.resize(offset, 0);
out.extend_from_slice(sample);
out.extend(box_bytes(b"mdat", sample));
out
}