Skip to content

Studio: check the weight index of a module path that only reads as the root - #16212

Merged
danielhanchen merged 7 commits into
mainfrom
dh/fix-st-module-dotdot-index
Nov 4, 2026
Merged

danielhanchen merged 7 commits into
mainfrom
dh/fix-st-module-dotdot-index

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Problem

escaping_weight_references reads each Sentence Transformers module folder named in modules.json and flags weight-index entries that point outside the model folder. A module path that normalizes to . as text is treated as the model root, whose index was already read, so it is skipped.

On POSIX the kernel follows a symlink before it applies .., so link/.. opens the folder beside the link's target, not the model root. A local model folder laid out like this passes the gate:

model/
  modules.json                     path: "link/.."
  link -> model/deep/child
  deep/model.safetensors.index.json   weight_map: {"w": "../../outside.safetensors"}

Sentence Transformers passes link/.. as the subfolder, and transformers' get_checkpoint_shard_files returns model/link/../../../outside.safetensors, which opens a file next to the model folder. On current main the gate returns [] for this folder.

Change

When a module path's .. climbs through a link, so its real path differs from its spelled path (link/.., link/../x), the module's index is read and each name is judged from where the module really lands: rooted / drive-qualified names, a .. that leaves the folder, or a shard link that resolves outside are flagged. Module paths without such a .. (every real Sentence Transformers layout: "", 0_Transformer, 1_Pooling) keep the existing check unchanged.

Tests

  • New test_account_path_confinement.py::test_a_module_path_that_reads_as_the_root_but_lands_elsewhere_has_its_index_read builds the layout above. Main: 1 failed (the gate returns []). This branch: 1 passed, and the same layout with a shard that stays in deep/ still passes. Each arm imported its own file_security.py.

  • New test_a_module_path_climbing_through_a_link_into_a_subfolder_is_judged_where_it_lands covers link/../x with a shard out/../s.safetensors through a link: fails on the earlier head of this branch, passes now. transformers 4.57.6 get_checkpoint_shard_files(subfolder="link/../x") opens the outside file for that layout.

  • A standalone check through the real transformers get_checkpoint_shard_files (opens the outside file, then asks the gate) passes on this branch.

  • test_account_path_confinement.py + test_file_security.py: 109 passed.

  • test_consent_gate.py, test_embedding_model_security_gate.py, test_security_gate_consistency.py, test_load_downloads.py, test_training_cached_start.py, test_offline_embedding_minimal.py, test_export_absolute_paths.py: the same results on main and this branch. The one failure on both is test_registered_absolute_export_folder_is_discoverable, from a module missing in this environment.

  • test_a_dot_named_module_folder_index_outside_the_model_is_flagged (from Check the weight index of dot-named Sentence Transformers module folders #14952) now skips on Windows: Win32 strips trailing dots, so its ... folders cannot be created there (it failed 5 cases on windows-latest before this PR touched it). Cross-platform staging: ubuntu 60 passed, macOS 59 passed / 1 skipped, Windows 37 passed / 22 skipped, 0 failed.

Not covered

  • Windows was not run. There ntpath collapses .. before it follows links, so link/.. is the model root and the new branch does not run.
  • No GPU needed. The change only reads small JSON index files.

…l root but lands elsewhere

A Sentence Transformers module path like link/.. normalizes to "." as text, so its index was skipped as the model root's. On POSIX the kernel follows the link before the "..", so the folder opened is beside the link's target and its index can name shards outside the model folder. Read that index and judge its names joined onto the module path as spelled.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T13:39:04.986716Z 01d4e5f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

[skip ci]
A module path like link/.. opens the link target's parent, so a shard named ../model.safetensors there can be the model root's own file. Resolve the module directory, join each shard name onto it and check containment against the model folder, instead of collapsing the spelled path as text. Rooted, drive-qualified and link escapes are still flagged.

[skip ci]
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 4, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 39b8528c12

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 4, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 01d4e5f862

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit c917be4 into main Nov 4, 2026
@danielhanchen
danielhanchen deleted the dh/fix-st-module-dotdot-index branch November 4, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant