in safetensors/src/tensor.rs [1472:1491]
fn test_validation_overflow() {
// u64::MAX = 18_446_744_073_709_551_615u64
// Overflow the shape calculation.
let serialized = b"O\x00\x00\x00\x00\x00\x00\x00{\"test\":{\"dtype\":\"I32\",\"shape\":[2,18446744073709551614],\"data_offsets\":[0,16]}}\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
match SafeTensors::deserialize(serialized) {
Err(SafeTensorError::ValidationOverflow) => {
// Yes we have the correct error
}
_ => panic!("This should not be able to be deserialized"),
}
// u64::MAX = 18_446_744_073_709_551_615u64
// Overflow the num_elements * total shape.
let serialized = b"N\x00\x00\x00\x00\x00\x00\x00{\"test\":{\"dtype\":\"I32\",\"shape\":[2,9223372036854775807],\"data_offsets\":[0,16]}}\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
match SafeTensors::deserialize(serialized) {
Err(SafeTensorError::ValidationOverflow) => {
// Yes we have the correct error
}
_ => panic!("This should not be able to be deserialized"),
}
}