Skip to content

Arbitrary code execution when decoding data with the Pickle codec

High
d-v-b published GHSA-jqc8-qjfv-5m6r Oct 20, 2026

Package

pip numcodecs (pip)

Affected versions

>= 0.17.0, < 0.17.1
>= 0.16.0, < 0.16.6
>= 0.1.0, < 0.15.2

Patched versions

0.17.1
0.16.6
0.15.2

Description

Summary

The numcodecs.pickles.Pickle codec decodes data by calling pickle.loads on
the input buffer. Deserializing untrusted pickle data can execute arbitrary code
during decoding. Because the Pickle codec is registered by default and is
selected from the codec id stored in array metadata, a maliciously crafted
array can cause arbitrary code execution in the reading process the moment a
chunk is read — the victim never has to choose the codec or call pickle
themselves.

Details

numcodecs codecs are looked up by a string id. get_codec({"id": "pickle"})
resolves to the Pickle class, which is registered at import time. Array
containers such as Zarr v2 store the codec id and its configuration in the
array's metadata (.zarray compressor / filters fields). When a chunk is
read, the library instantiates the codec named in that metadata and calls its
decode method on the chunk bytes.

For the Pickle codec, decode runs pickle.loads on those bytes. The Python
pickle format is not a safe data format: a pickle stream can instruct the
interpreter to import modules and invoke callables during loading (see the
security warning in the standard library pickle documentation). The vulnerable
operation is the decode path, numcodecs.pickles.Pickle.decode →
pickle.loads(buf). encode is not affected.

The codec id that selects Pickle, and the chunk bytes fed to it, both come from
the array being read. Selecting the dangerous codec is therefore entirely under
the attacker's control via the stored metadata; no call to pickle or to the
Pickle codec appears in the victim's own code.

Proof of concept

The following demonstrates that decoding attacker-controlled bytes invokes a
callable chosen by those bytes. It uses a harmless, observable side effect (a
module-level flag) in place of any real payload; a __reduce__ method can name
any importable callable, which is the root of the issue.

import pickle
import numcodecs

executed = {"ran": False}

def _mark():
    # stands in for an attacker-chosen callable
    executed["ran"] = True

class Evil:
    def __reduce__(self):
        return (_mark, ())

# Attacker produces bytes; victim's library decodes them.
malicious_bytes = pickle.dumps(Evil())
numcodecs.Pickle().decode(malicious_bytes)

assert executed["ran"] is True  # the callable ran during decode

In a realistic attack the victim never calls Pickle directly. Instead the
codec id travels in array metadata (e.g. a Zarr v2 .zarray compressor or
filters entry set to {"id": "pickle"}), and the malicious bytes are stored as
an ordinary chunk. Reading any such chunk resolves the pickle id via
get_codec and runs Pickle.decode on the attacker's bytes, so simply opening
and reading the array triggers execution.

Impact

An attacker who can influence the bytes or metadata that a victim reads — for
example by publishing a dataset, sharing a file, or serving array data over a
network — can achieve arbitrary code execution in the victim's process, with the
victim's privileges. The victim only needs to read the array with a stack that
uses numcodecs for decoding (for example Zarr v2).

This affects numcodecs installed from any source, including conda-forge; the
"Affected products" versions above use the pip ecosystem because that is what
GitHub records, but the same version ranges apply to the conda-forge package.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
Required
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H

CVE ID

No known CVE

Weaknesses

Deserialization of Untrusted Data

The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid. Learn more on MITRE.

Credits