Repository navigation
Studio: check the weight index of a module path that only reads as the root - #16212
Conversation
…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.
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. |
[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]
[skip ci]
… where it lands [skip ci]
[skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
Problem
escaping_weight_referencesreads each Sentence Transformers module folder named inmodules.jsonand 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
.., solink/..opens the folder beside the link's target, not the model root. A local model folder laid out like this passes the gate:Sentence Transformers passes
link/..as the subfolder, and transformers'get_checkpoint_shard_filesreturnsmodel/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_readbuilds the layout above. Main: 1 failed (the gate returns[]). This branch: 1 passed, and the same layout with a shard that stays indeep/still passes. Each arm imported its ownfile_security.py.New
test_a_module_path_climbing_through_a_link_into_a_subfolder_is_judged_where_it_landscoverslink/../xwith a shardout/../s.safetensorsthrough a link: fails on the earlier head of this branch, passes now. transformers 4.57.6get_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 istest_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
ntpathcollapses..before it follows links, solink/..is the model root and the new branch does not run.