interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-inference-abi / tests / checkpoint_security.rs

71 lines · 2774 bytes Raw Blame History
1//! Offline real-loader regressions, also runnable against origin/main.
2use aien_inference_abi::checkpoint::{checkpoint_files, load_checkpoint_with_catalog};
3use std::{fs, path::Path};
4
5fn shard(path: &Path) {
6 let header = br#"{"w":{"dtype":"BF16","shape":[1],"data_offsets":[0,2]}}"#;
7 let mut bytes = (header.len() as u64).to_le_bytes().to_vec();
8 bytes.extend_from_slice(header);
9 bytes.extend_from_slice(&[0, 0]);
10 fs::write(path, bytes).unwrap();
11}
12
13#[test]
14fn index_cannot_load_absolute_parent_or_symlink_shards() {
15 let temp = std::env::temp_dir().join(format!("sc-sec-5-{}", std::process::id()));
16 fs::create_dir(&temp).unwrap();
17 let model = temp.join("model");
18 fs::create_dir(&model).unwrap();
19 shard(&temp.join("outside.safetensors"));
20 shard(&model.join("inside.safetensors"));
21 std::os::unix::fs::symlink(
22 temp.join("outside.safetensors"),
23 model.join("link.safetensors"),
24 )
25 .unwrap();
26 let catalog = vec![("w".into(), vec![1])];
27 let mut accepted = Vec::new();
28 for name in [
29 temp.join("outside.safetensors").display().to_string(),
30 "../outside.safetensors".into(),
31 "link.safetensors".into(),
32 ] {
33 fs::write(
34 model.join("model.safetensors.index.json"),
35 serde_json::json!({"weight_map":{"w":name}}).to_string(),
36 )
37 .unwrap();
38 if load_checkpoint_with_catalog(&model, &catalog).is_ok() {
39 accepted.push(name);
40 }
41 }
42 // Negative control: a regular shard in the checkpoint directory must load.
43 fs::write(
44 model.join("model.safetensors.index.json"),
45 r#"{"weight_map":{"w":"inside.safetensors"}}"#,
46 )
47 .unwrap();
48 assert!(load_checkpoint_with_catalog(&model, &catalog).is_ok());
49 fs::remove_dir_all(temp).unwrap();
50 assert!(
51 accepted.is_empty(),
52 "escaped index shards were loaded: {accepted:?}"
53 );
54}
55
56#[test]
57fn oversized_and_nonregular_files_are_rejected_before_reads() {
58 let temp = std::env::temp_dir().join(format!("sc-sec-5-bounds-{}", std::process::id()));
59 fs::create_dir(&temp).unwrap();
60 let sparse = temp.join("model.safetensors");
61 let file = fs::File::create(&sparse).unwrap();
62 // Filesystem-safe sparse size exceeds the documented production shard cap.
63 file.set_len(274877906945).unwrap();
64 let oversized_accepted = checkpoint_files(&sparse).is_ok();
65 fs::remove_file(&sparse).unwrap();
66 std::os::unix::fs::symlink("/dev/null", &sparse).unwrap();
67 let nonregular_accepted = checkpoint_files(&sparse).is_ok();
68 fs::remove_dir_all(temp).unwrap();
69 assert!(!oversized_accepted, "unbounded file length accepted");
70 assert!(!nonregular_accepted, "nonregular/symlink input accepted");
71}