Skip to content

fix: reject cyclic safetensors index references - #2055

Closed
Yi-111-a wants to merge 1 commit into
leejet:masterfrom
Yi-111-a:fix-cyclic-safetensors-index
Closed

Yi-111-a wants to merge 1 commit into
leejet:masterfrom
Yi-111-a:fix-cyclic-safetensors-index

Conversation

@Yi-111-a

Copy link
Copy Markdown
Contributor

Fixes #2052

What changed and why

ModelLoader::parse_file treats every .json path as a safetensors index and then loads each weight_map shard through parse_file again. An index whose shard path resolves to that same index (or to another index that refers back) never hits a missing-file error, so the loader logs using safetensors index format until the process is killed or overflows the stack.

The loader now remembers the indexes it is already reading. A shard that resolves to one of those paths returns cyclic safetensors index reference and the convert command exits with status 1. A shard that is simply missing still reports the missing file.

Verification

CPU build from b167b94, matching the report:

cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DSD_SERVER_BUILD_FRONTEND=OFF -DSD_WEBP=OFF -DSD_WEBM=OFF -DGGML_NATIVE=OFF

sd-cli --mode convert on three fixtures:

  • {"weight_map":{"tensor":"model.safetensors.index.json"}} exits 1 after one load line and cyclic safetensors index reference.
  • a pointing at b and b pointing at a exits 1 after the two index load lines, with the same error.
  • An index pointing at a nonexistent .safetensors file still fails with cannot inspect model source 'missing.safetensors': No such file or directory.

A weight_map entry that points back at its own index, or at another index
that points back, made parse_file recurse until the process was killed.
Track indexes already being loaded and return a normal error instead.
@leejet

leejet commented Sep 25, 2026

Copy link
Copy Markdown
Owner

Superseded by #2058.

@leejet leejet closed this Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Self-referential safetensors index repeatedly reloads itself

2 participants