Guard texture and XMA offsets against overflow

This commit is contained in:
Vanthys committed 2026-11-24 00:46:54 +01:00
1 parent 97c78d1087
commit e158d95247
2 files changed
+45 -2

No files matched your search

+8 -1
View File
@@ -53,7 +53,8 @@ pub struct Packet {
}
pub fn packet(data: &[u8], index: usize) -> Option<Packet> {
let b = data.get(index * PACKET_BYTES..index * PACKET_BYTES + 4)?;
let start = index.checked_mul(PACKET_BYTES)?;
let b = data.get(start..)?.get(..4)?;
let h = u32::from_be_bytes([b[0], b[1], b[2], b[3]]);
Some(Packet {
frames: h >> 26,
@@ -1112,6 +1113,12 @@ mod tests {
}
}
#[test]
fn packet_rejects_out_of_range_indices_and_partial_headers() {
assert!(packet(&[0; 4], usize::MAX / PACKET_BYTES + 1).is_none());
assert!(packet(&[0; 3], 0).is_none());
}
#[test]
fn packet_headers_and_frame_walk() {
// Two packets: frame A (100 bits) and B (16300 bits, crossing into