Guard texture and XMA offsets against overflow
This commit is contained in:
1 parent
b9aff99b98
commit
7078f1e744
2 files changed
+45
-2
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user