Lion Cipher Lab

Read a safetensors model file by hand and reject a malformed one before loading it

Why it matters

People call safetensors a safe model format, and that is a claim worth checking yourself. Python's own documentation warns that unpickling untrusted data can run arbitrary code, and many older model formats are pickles. Safetensors was designed as the alternative: a short length, a JSON description, then raw numbers, with no place to put a function to call. Because the layout is so small you can read it with a few lines of Python and write a validator that refuses anything odd before any library touches it. Doing that once shows what the format guarantees (no code) and what it does not…

What you'll learn

Steps in this lab

  1. Start from the problem: a pickle can carry code
  2. Learn the layout from the specification
  3. Build a tiny model file with only the standard library
  4. Write a validator that never loads a tensor
  5. Feed it two damaged files
  6. Compare with the real library (optional)
  7. What the format guarantees, and what it does not
  8. Clean up

Open the full interactive lab →

Keep learning