]> khamidou — GitHub mirrors - safetensors.git/commitdiff
Adding last missing test for validate. (#225)
authorNicolas Patry <patry.nicolas@protonmail.com>
Thu, 6 Apr 2023 08:27:13 +0000 (10:27 +0200)
committerGitHub <noreply@github.com>
Thu, 6 Apr 2023 08:27:13 +0000 (10:27 +0200)
safetensors/src/tensor.rs

index bb6ff6041c834ef9bb864d411268770382af2e44..c89d640aa027c80a0ece36a0eede33c9b6b85c36 100644 (file)
@@ -1082,6 +1082,17 @@ mod tests {
         assert_eq!(tensor.data(), b"");
     }
 
+    #[test]
+    fn test_invalid_info() {
+        let serialized = b"<\x00\x00\x00\x00\x00\x00\x00{\"test\":{\"dtype\":\"I32\",\"shape\":[2,2],\"data_offsets\":[0, 4]}}";
+        match SafeTensors::deserialize(serialized) {
+            Err(SafeTensorError::TensorInvalidInfo) => {
+                // Yes we have the correct error
+            }
+            _ => panic!("This should not be able to be deserialized"),
+        }
+    }
+
     #[test]
     fn test_validation_overflow() {
         // u64::MAX =  18_446_744_073_709_551_615u64