security: remove allow_pickle=True from NumpyLayout (CVE-2019-6446 bypass)#3013
Open
SnailSploit wants to merge 1 commit intogoogle:mainfrom
Open
security: remove allow_pickle=True from NumpyLayout (CVE-2019-6446 bypass)#3013SnailSploit wants to merge 1 commit intogoogle:mainfrom
SnailSploit wants to merge 1 commit intogoogle:mainfrom
Conversation
…pass) np.load(path, allow_pickle=True) overrides NumPy's safety default (CVE-2019-6446), enabling arbitrary code execution via malicious .npz checkpoint files. The _reconstruct_npz_contents() function then calls .item() on object-dtype arrays, which triggers pickle deserialization of attacker-controlled data. Changes: - Remove allow_pickle=True from np.load() call in _load_numpy() - Replace .item() deserialization path with ValueError for object arrays - Add security note to _reconstruct_npz_contents docstring Backward compatible: checkpoints with numeric/string arrays (standard for ML model weights) are unaffected.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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
Remove
allow_pickle=Truefromnp.load()inNumpyLayoutto prevent arbitrary code execution via malicious.npzcheckpoint files.Security Issue
_load_numpy()callsnp.load(path, allow_pickle=True), which overrides the safety default introduced by NumPy in response to CVE-2019-6446. Combined with_reconstruct_npz_contents()calling.item()on object-dtype arrays, this creates a remote code execution path: an attacker who controls a checkpoint file can embed a pickled Python object that executes arbitrary code when loaded.Attack scenario: A user downloads a model checkpoint from an untrusted source (e.g., a public model hub). The
.npzfile contains a crafted object-dtype array whose.item()triggerspickle.loads()internally, executing attacker-controlled Python code.Changes
_load_numpy(): Removedallow_pickle=Truefromnp.load()call, restoring NumPy's safe default (allow_pickle=False)._reconstruct_npz_contents(): Replaced thedtype == object/.item()deserialization path with aValueErrorthat clearly explains why object arrays are rejected.Backward Compatibility
Checkpoints containing only numeric/string-typed arrays (the standard case for ML model weights) are unaffected. Checkpoints that relied on pickling arbitrary Python objects into
.npzfiles will now raise a clear error. This is the intended behavior — loading arbitrary pickled objects from untrusted files is the vulnerability being fixed.