security: remove allow_pickle=True from NumpyLayout (CVE-2019-6446 bypass)
Summary
Remove allow_pickle=True from np.load() in NumpyLayout to prevent arbitrary code execution via malicious .npz checkpoint files.
Security Issue
_load_numpy() calls np.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 .npz file contains a crafted object-dtype array whose .item() triggers pickle.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 .npz files will now raise a clear error. This is the intended behavior — loading arbitrary pickled objects from untrusted files is the vulnerability being fixed.
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.