fix(transformers): validate archive extraction paths#28777
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Hardens the TensorFlow checkpoint download/conversion utility by adding a shared “safe archive extraction” helper to prevent directory traversal when unpacking .tar.gz and .zip checkpoint archives, and adds regression coverage for traversal-style archive members.
Changes:
- Added
_is_safe_archive_member+safe_extract_archive()and routed checkpoint extraction through it. - Uses Python tarfile extraction filters (
filter="data") when available. - Added regression tests to ensure
../archive members are rejected for both tar.gz and zip.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| onnxruntime/python/tools/transformers/convert_tf_models_to_pytorch.py | Introduces path validation and a unified safe extraction helper for tar/zip archives used in checkpoint download. |
| test_convert_tf_models_to_pytorch.py | Adds regression tests for rejecting traversal entries in tar.gz/zip archives. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- _is_safe_archive_member: normalize separators and treat commonpath ValueError (mixed-drive paths) as unsafe - refuse tar extraction when the data filter is unavailable; reject symlink/hardlink members - move regression test under onnxruntime/test/python/transformers/ and resolve module path via __file__ - add backslash-traversal and symlink rejection tests
skottmckay
approved these changes
Jun 4, 2026
skottmckay
left a comment
Contributor
There was a problem hiding this comment.
Bit dubious that it was worth us wasting our time on this issue. Seems extremely low priority/Won't Fix given it's a script a user would have to manually run.
tianleiwu
enabled auto-merge (squash)
June 4, 2026 15:03
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
This PR hardens TensorFlow checkpoint archive extraction in the transformer conversion utility by validating archive member paths before extraction and using Python's safe tar extraction filter when available. It also adds regression tests to confirm traversal-style archive members are rejected for both tar.gz and zip inputs.
Key Changes
onnxruntime/python/tools/transformers/convert_tf_models_to_pytorch.py.extractall()usage with path validation to prevent directory traversal outside the target checkpoint directory.test_convert_tf_models_to_pytorch.pyto cover malicious../archive members.Testing
./.venv/bin/python -m pytest test_convert_tf_models_to_pytorch.py