Repository navigation
Check the weight index of dot-named Sentence Transformers module folders - #14952
Merged
Merged
Conversation
A modules.json path such as '...', './...' or '..../' is an ordinary folder, not the model root, but escaping_weight_references skipped any path made of only dots and slashes, so its index was never read. Skip only paths that normalize to '.', and judge the index against both the Windows and POSIX spelling of the folder.
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
shimmyshimmer
pushed a commit
to shimmyshimmer/unsloth-staging-4
that referenced
this pull request
Nov 4, 2026
…e root (unslothai#16212) ## 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: ```text 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 unslothai#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows up #14527.
What was wrong
escaping_weight_referencesskipped everymodules.jsonmodule path made only of dots and slashes (if not sub.strip("./\\"): continue). #14527 moved the escape check ahead of that skip, which catches..,../..,/and\, but...,./...and..../are ordinary folder names: they do not normalize to.., so they passed the escape check and were then skipped, and the index inside them was never read. Sentence Transformers accepts such a path (_validate_relative_pathonly rejects rooted paths and..components) and opensPath(model_dir, sub); transformers then joins each shard name onto that folder (os.path.join(path, subfolder, f)inget_checkpoint_shard_files). So an index in.../naming../../outside.safetensorsloads a file from outside the model folder without being flagged.Fix
.("",.,./) is treated as the model root and skipped.Tests
test_account_path_confinement.py:...,./...,..../,....,0_Transformer/...and.\...(POSIX only) are flagged when their index escapes and pass when it does not;0_Transformer,.and./keep their verdict.file_security: 716 passed; 2 failures there also fail on main (a module missing from the test environment).Not run: Windows (backslash cases checked on Linux only), a real Sentence Transformers load of a
...folder (loader behaviour read from the 6.2.0 source and the transformers shard resolver), a live Studio server.