Repository navigation
reject symlinks to directories during serialization - #673
Merged
Merged
Conversation
file.Serializer.serialize and file_shard.Serializer.serialize walk the
model with glob("**/*"), which never descends into a symlink that points
to a directory. With allow_symlinks enabled the link passes
check_file_or_directory, is not a file, and is skipped, so every file
beneath it is left out of the manifest with no error. A model signed with
a symlinked weights directory carries no digests for anything under that
link, and changing or adding files there afterwards still verifies clean.
Raise on a symlink to a directory in both serializers, unless it is
covered by the ignore paths, and keep accepting a model root that is
itself a symlink since the walk does follow that one. The check sits in
the walk loop, next to the place that fails to descend, so both signing
and verification refuse the model instead of silently producing or
accepting a partial manifest.
Signed-off-by: Itecz Solution <support@itecz.au>
stefanberger
approved these changes
Oct 2, 2026
mihaimaruseac
approved these changes
Oct 2, 2026
mihaimaruseac
left a comment
Member
There was a problem hiding this comment.
Thank you!
This makes sense and probably we would reach a state where symlinks will always be an error.
Contributor
Author
|
Thanks for the review and the merge on this one. |
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.
Summary
file.Serializer.serializeandfile_shard.Serializer.serializewalk the model withglob("**/*"), which never descends into a symlink that points to a directory. Withallow_symlinksenabled the link passescheck_file_or_directory, is not a file, and is skipped, so every file beneath it is left out of the manifest with no error. A model signed with a symlinked weights directory carries no digests for anything under that link, and changing or adding files there afterwards still verifies clean. Related to the symlink discussion in #666, though this gap is not in that list.Raise on a symlink to a directory in both serializers, unless it is covered by the ignore paths, and keep accepting a model root that is itself a symlink since the walk does follow that one. The check sits in the walk loop, next to the place that fails to descend, so both signing and verification refuse the model instead of silently producing or accepting a partial manifest. Regression tests cover the rejection, the ignored-link case and the symlinked root for both serializers.
To reproduce before the fix: put
weights -> /some/dir(containing a file) inside a model directory and hash it withset_allow_symlinks(True). The manifest lists only the files outside the link, and rewriting or adding files under/some/dirleaves the manifest unchanged.Checklist