Python pickles (.bin, .pt, .pth, .ckpt, .pkl) run whatever they hold when loaded, as the engine's user, on the node; that is how the malicious models found on Hugging Face work. The node refuses such a source, or a mirror set holding one, before fetching anything. A model added with one, or given one, is refused, while one already in the catalog still loads and is refused by its node with the same words. vLLM and SGLang downloading a model by its id get --load-format safetensors. The mirror page marks the file. allow_pickle: true on a model lets it through on purpose, carried to the node in EngineProfile.allow_pickle. BACKLOG M lists the rest: checksums against Hugging Face on every path, its own scan, trusted publishers, engines without the internet, an eval before an untrusted model serves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package weights
|
|
|
|
import (
|
|
"errors"
|
|
"sync/atomic"
|
|
"testing"
|
|
)
|
|
|
|
func TestPickleFormatsAreKnownByTheirNames(t *testing.T) {
|
|
for name, want := range map[string]bool{
|
|
"pytorch_model.bin": true, "model.ckpt": true, "x.PT": true, "w.pth": true, "a.pkl": true,
|
|
"https://h/r/resolve/main/model.ckpt?download=true": true,
|
|
"model.safetensors": false, "m-Q4_K_M.gguf": false, "Qwen/Qwen2.5-7B-Instruct": false,
|
|
"config.json": false, "": false,
|
|
} {
|
|
if got := Pickled(name); got != want {
|
|
t.Errorf("Pickled(%q) = %v, want %v", name, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAPickleFileIsRefusedBeforeItIsFetched(t *testing.T) {
|
|
var hits atomic.Int64
|
|
srv := serveBytes(t, []byte("not really a pickle"), &hits)
|
|
f := &Fetcher{CacheDir: t.TempDir()}
|
|
|
|
_, err := f.Ensure(t.Context(), srv.URL+"/model.ckpt", false)
|
|
if !errors.Is(err, ErrPickle) {
|
|
t.Fatalf("a .ckpt was not refused: %v", err)
|
|
}
|
|
if hits.Load() != 0 {
|
|
t.Errorf("the refused file was fetched %d times", hits.Load())
|
|
}
|
|
if _, err := f.Ensure(t.Context(), srv.URL+"/model.ckpt", true); err != nil {
|
|
t.Errorf("allowed, the .ckpt was still refused: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestASetWithAPickleFileIsRefusedWhole(t *testing.T) {
|
|
f, srv, hits := mirrorOf(t, map[string]string{
|
|
"pytorch_model.bin": "pickle",
|
|
"config.json": "{}",
|
|
})
|
|
if _, err := f.Ensure(t.Context(), srv.URL+"/m/v/", false); !errors.Is(err, ErrPickle) {
|
|
t.Fatalf("a set holding pytorch_model.bin was not refused: %v", err)
|
|
}
|
|
if *hits != 0 {
|
|
t.Errorf("%d files of the refused set were fetched", *hits)
|
|
}
|
|
if _, err := f.Ensure(t.Context(), srv.URL+"/m/v/", true); err != nil {
|
|
t.Errorf("allowed, the set was still refused: %v", err)
|
|
}
|
|
}
|