
Proof-of-concept and patch for CVE-2026-57845: pickle deserialization RCE in Hugging Face datasets' pandas builder, with reproduction script and remediation guidance.
<= 5.1.0 Pandas Pickle RCESeverity: High, CVSS 3.1 8.8
Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
Affected: all Hugging Face datasets versions <= 5.1.0
Component: datasets.packaged_modules.pandas.pandas
CWE: CWE-502 (Deserialization of Untrusted Data)
Discovered and reported by: Sai Teja Erukude
Hugging Face datasets versions up to and including 5.1.0 allow arbitrary
Python code execution when loading attacker-controlled pickle files through
the deprecated but still registered pandas packaged builder.
The builder resolves caller-supplied data_files, opens each file as bytes,
and passes the file object directly to pandas.read_pickle() before converting
the result to an Arrow table:
with open(file, "rb") as f:
pa_table = pa.Table.from_pandas(pd.read_pickle(f))
Python pickle deserialization can execute attacker-selected code. When a victim
loads a malicious pickle-backed dataset with
datasets.load_dataset("pandas", data_files=...), the payload executes with
the victim process's privileges before Arrow conversion or feature validation.
An attacker who can cause a victim to load an attacker-controlled pickle through
the pandas builder may execute arbitrary Python code in the victim process.
This can affect data analysis, machine learning, and automation workflows that
load datasets from untrusted projects, repositories, downloads, or shared files.
The attacker does not need privileges in the victim environment, but the victim
must load the malicious dataset, consistent with the report's user-interaction
requirement (UI:R).
Depending on the local environment, this may allow:
The vulnerable path is the pandas packaged builder:
datasets.load_dataset("pandas", data_files=...)
-> dataset_module_factory(...)
-> registered pandas packaged builder
-> Pandas._split_generators(...)
-> resolve or download caller-supplied data_files
-> Pandas._generate_tables(...)
-> open(file, "rb")
-> pandas.read_pickle(f)
-> pyarrow.Table.from_pandas(...)
The PoC creates a pickle object whose __reduce__() method specifies a callable
that writes a harmless local marker file and returns a valid
pandas.DataFrame. During deserialization, that callable executes before the
builder converts the returned DataFrame to an Arrow table. Dataset loading then
completes normally and returns one row.
The runner invokes the real datasets.load_dataset() API from the installed
package. A fresh local cache and removal of the previous marker ensure that the
saved result demonstrates execution during dataset loading.
Deprecating the builder or validating the returned DataFrame does not prevent execution during unpickling. The pandas documentation also warns against loading pickle data from untrusted sources.
run_poc.py generates attacker-controlled.pkl, loads it through
the pandas builder, and records execution evidence.
Run in a local test environment only. To reproduce the version shown in the saved evidence on Windows:
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install "datasets==5.1.0"
.\.venv\Scripts\python.exe -B run_poc.py
The included requirements.txt currently specifies
datasets<=5.0.1. It can be installed with
python -m pip install -r requirements.txt to test that earlier range, but it
does not select the 5.1.0 installation used in the saved evidence. The explicit
pin above reproduces that installation's datasets version.
Expected evidence on the demonstrated vulnerable version:
datasets_version: 5.1.0
installed_package: True
load_error: None
row_count: 1
first_row: {'value': 'benign dataframe returned after pickle execution'}
marker_before_load_dataset: False
marker_after_load_dataset: True
marker_contents:
datasets_pandas_pickle_rce_triggered
success: True
The important evidence is that the marker is absent before load_dataset(),
appears during loading, and contains the expected string while dataset loading
completes successfully and returns the expected row.
The payload's execution effect is a local marker-file write:
datasets_pandas_pickle_rce_triggered
The runner also writes the generated pickle, cache, and evidence files. Each run
replaces attacker-controlled.pkl, marker.txt, cache/, and evidence/ in the
PoC directory; preserve existing evidence before rerunning it.
Saved artifacts:
The narrow fix replaces the entire body of Pandas._generate_tables() with
an unconditional error before any file is opened or passed to
pandas.read_pickle():
def _generate_tables(self, files):
raise ValueError(PANDAS_PICKLE_DISABLED_ERROR)
The error explains the pickle execution risk and directs callers to Parquet,
Arrow, CSV, JSON, or Dataset.from_pandas() for an existing DataFrame. This
blocks the reported code-execution path for every filename, including trusted
pickles; it does not attempt to determine which pickle files are trustworthy.
The builder remains registered and can still be constructed through
load_dataset_builder("pandas", ...) or Pandas(...). File resolution and
downloads may happen before table generation fails. With streaming, the error
occurs when the dataset is iterated. A compatible prepared Arrow cache can
still be reused without calling _generate_tables() or unpickling the input.
Changing the builder source changes its hash, so older caches may no longer
match automatically. This patch does not reject the builder name in load.py.
For example, load Parquet through its dedicated builder:
from datasets import load_dataset
dataset = load_dataset("parquet", data_files="data.parquet", split="train")
Regression tests cover fresh loading, streaming iteration, direct table
generation, builder construction, prepared Arrow cache reuse, and supported
replacement formats. They verify that pandas.read_pickle() is never reached
and that direct table generation does not open files. Checking an object's
type after unpickling is too late. Renaming a file, emitting a warning, or converting an
untrusted pickle to another format by first unpickling it does not address the
execution risk.
See fix.md for the narrow patch, migration guidance, and
verification commands. The patch is applied to this checkout's source;
existing installed packages must be patched or replaced separately. This
repository links the related upstream pull request below; a confirmed fixed
release is not documented here.
Discovered and reported by Sai Teja Erukude.
Disclosure was coordinated through VulnCheck.