Repository navigation
[Data] Gate unsafe deserialization in WebDataset default decoder - #63469
Merged
Merged
Conversation
…nd env var The default decoder in `read_webdataset` runs `pickle.loads` on `.pkl/.pickle` files and `torch.load(weights_only=False)` on `.pt/.pth` files from attacker-controlled TAR archives, enabling arbitrary code execution. Gate these branches behind `RAY_DATA_WEBDATASET_ALLOW_UNSAFE_DESERIALIZATION=1` and point users to the existing `decoder` parameter as the safe escape hatch. Signed-off-by: Balaji Veeramani <[email protected]>
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cc6a31b. Configure here.
iamjustinhsu
approved these changes
May 18, 2026
bveeramani
enabled auto-merge (squash)
May 18, 2026 21:34
_allow_unsafe_deserialization() checked os.environ on workers, which never saw monkeypatch.setenv from the driver. Instead, read the env var in WebDatasetDatasource.__init__ (driver-side), store the result as self._allow_unsafe_deserialization, and pass it to _default_decoder via functools.partial. The datasource is pickled to workers, so the flag propagates automatically. Also fix custom decoder test key match (pkl, not .pkl). Signed-off-by: Balaji Veeramani <[email protected]>
Signed-off-by: Balaji Veeramani <[email protected]>
… messages Signed-off-by: Balaji Veeramani <[email protected]>
bveeramani
enabled auto-merge (squash)
May 19, 2026 01:11
TruongQuangPhat
pushed a commit
to cyhapun/ray-fix-issue
that referenced
this pull request
May 27, 2026
…-project#63469) ## Description The default decoder in `read_webdataset` runs `pickle.loads` on `.pkl/.pickle` files and `torch.load(weights_only=False)` on `.pt/.pth` files from attacker-controlled TAR archives, enabling arbitrary code execution with no opt-in. This is the same class of bug as GHSA-mw35-8rx3-xf9r (patched in 2.55.0 for Parquet), but in a different code path that was not addressed. This PR gates the unsafe `.pkl/.pickle` and `.pt/.pth` branches in `_default_decoder` behind the `RAY_DATA_WEBDATASET_ALLOW_UNSAFE_DESERIALIZATION=1` environment variable. The error message points users to the existing `decoder` parameter on `ray.data.read_webdataset()` as the safe escape hatch for custom deserialization. ## Related issues Fixes GHSA-hhrp-gw25-jr43 ## Additional information - Existing tests that rely on `.pt` round-trip encoding/decoding now use a `monkeypatch.setenv` fixture to opt in - New tests verify: rejection of all four unsafe extensions by default, opt-in via env var, and bypass via custom `decoder` callable --------- Signed-off-by: Balaji Veeramani <[email protected]> Signed-off-by: phattruong <[email protected]>
alexandrplashchinsky
pushed a commit
to alexandrplashchinsky/ray-alex
that referenced
this pull request
May 29, 2026
…-project#63469) ## Description The default decoder in `read_webdataset` runs `pickle.loads` on `.pkl/.pickle` files and `torch.load(weights_only=False)` on `.pt/.pth` files from attacker-controlled TAR archives, enabling arbitrary code execution with no opt-in. This is the same class of bug as GHSA-mw35-8rx3-xf9r (patched in 2.55.0 for Parquet), but in a different code path that was not addressed. This PR gates the unsafe `.pkl/.pickle` and `.pt/.pth` branches in `_default_decoder` behind the `RAY_DATA_WEBDATASET_ALLOW_UNSAFE_DESERIALIZATION=1` environment variable. The error message points users to the existing `decoder` parameter on `ray.data.read_webdataset()` as the safe escape hatch for custom deserialization. ## Related issues Fixes GHSA-hhrp-gw25-jr43 ## Additional information - Existing tests that rely on `.pt` round-trip encoding/decoding now use a `monkeypatch.setenv` fixture to opt in - New tests verify: rejection of all four unsafe extensions by default, opt-in via env var, and bypass via custom `decoder` callable --------- Signed-off-by: Balaji Veeramani <[email protected]> Signed-off-by: Alexandr Plashchinsky <[email protected]>
400Ping
pushed a commit
to 400Ping/ray
that referenced
this pull request
Aug 18, 2026
…-project#63469) ## Description The default decoder in `read_webdataset` runs `pickle.loads` on `.pkl/.pickle` files and `torch.load(weights_only=False)` on `.pt/.pth` files from attacker-controlled TAR archives, enabling arbitrary code execution with no opt-in. This is the same class of bug as GHSA-mw35-8rx3-xf9r (patched in 2.55.0 for Parquet), but in a different code path that was not addressed. This PR gates the unsafe `.pkl/.pickle` and `.pt/.pth` branches in `_default_decoder` behind the `RAY_DATA_WEBDATASET_ALLOW_UNSAFE_DESERIALIZATION=1` environment variable. The error message points users to the existing `decoder` parameter on `ray.data.read_webdataset()` as the safe escape hatch for custom deserialization. ## Related issues Fixes GHSA-hhrp-gw25-jr43 ## Additional information - Existing tests that rely on `.pt` round-trip encoding/decoding now use a `monkeypatch.setenv` fixture to opt in - New tests verify: rejection of all four unsafe extensions by default, opt-in via env var, and bypass via custom `decoder` callable --------- Signed-off-by: Balaji Veeramani <[email protected]> Signed-off-by: 400Ping <[email protected]>
goutamvenkat-anyscale
added a commit
that referenced
this pull request
Nov 3, 2026
## Summary `read_images`, the `read_webdataset` default decoder, and the LeRobot image-camera decoder passed untrusted bytes straight to `PIL.Image.open` with no format restriction. PIL picks a plugin by **file signature, not extension**, so a payload named `a.jpg` that actually contains EPS bytes is routed to PIL's EPS plugin — which shells out to the external **Ghostscript** binary. On a host with a vulnerable Ghostscript this can execute code in the Ray worker. This is the image sibling of the `.pkl`/`.pt` decoder hardening done in GHSA-hhrp-gw25-jr43; that fix (#63469) added a deserialization guard but did not add an image-format allowlist. Fix: restrict all three decoders to a raster-format allowlist via `Image.open(..., formats=[...])`, so disallowed formats (EPS, etc.) are rejected before any plugin runs. The allowlist lives in one place (`_internal/datasource/image_utils.py`) so the readers can't drift apart. Addresses GHSA-pwm8-8ghq-qw5p. ## Before - `ray.data.read_images("a.jpg")` where `a.jpg` holds EPS bytes → PIL selects the EPS plugin → attempts to launch Ghostscript. - `ray.data.read_webdataset(tar)` with a member `0001.jpg` holding EPS bytes → same dispatch via the default decoder. - `ray.data.read_lerobot(...)` with an image-camera parquet cell holding EPS bytes → same dispatch in `_decode_image_frames`. - No allowlist: any format PIL can sniff is reachable from untrusted input. ## After - One shared allowlist, `_ALLOWED_PIL_FORMATS = ["PNG", "JPEG", "TIFF", "BMP", "GIF"]`, in `_internal/datasource/image_utils.py` (aligned with `ImageDatasource._FILE_EXTENSIONS`). - `read_images`: uses `_ALLOWED_PIL_FORMATS`. - LeRobot: uses `_ALLOWED_PIL_FORMATS`. This covers what LeRobot writes (PNG camera frames, TIFF depth maps) and JPEG frames common in Hub datasets. - WebDataset decoder: `_ALLOWED_WEBDATASET_PIL_FORMATS = _ALLOWED_PIL_FORMATS + ["PPM"]` (PPM covers the `ppm/pgm/pbm/pnm` extensions it handles). - A datasource that needs extra formats extends the shared list instead of defining its own. - Disallowed content (EPS, etc.) raises `UnidentifiedImageError` / a clear `ValueError` (`read_images`) **before** any PIL plugin executes — Ghostscript is never reached. Valid raster images decode exactly as before. - Behavior change: images in formats outside the allowlist (e.g. WebP) that PIL previously decoded are now rejected, including via `read_images(..., file_extensions=[...])`. ```mermaid flowchart TD subgraph Before subgraph BIO[Subsystem: IO] subgraph BC[datasource: image / webdataset / lerobot] B1[untrusted bytes] --> B2[PIL.Image.open no allowlist] B2 --> B3[plugin chosen by signature] B3 --> B4[EPS plugin -> Ghostscript] end end end subgraph After subgraph AIO[Subsystem: IO] AU["image_utils._ALLOWED_PIL_FORMATS"] subgraph AC[datasource: image / webdataset / lerobot] A1[untrusted bytes] --> A2["PIL.Image.open(formats=allowlist)"] A2 --> A3{format in allowlist?} A3 -- yes --> A4[decode raster image] A3 -- no --> A5[reject: UnidentifiedImageError / ValueError] end AU --> A2 end end classDef removed fill:#ffcdd2,stroke:#c62828,color:#000 classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000 class B4 removed class AU,A2,A3,A5 added ``` ## Subsystems IO (datasources: `image_utils.py` (new), `image_datasource.py`, `webdataset_datasource.py`, `lerobot_datasource.py`). Behavioral change is the format gating; no change to block/format handling of valid images. ## Testing - `pytest python/ray/data/tests/datasource/test_webdataset.py -k "disallowed_image_format or allows_png"` → **2 passed**. - Added `test_image.py::TestReadImages::test_disallowed_format_not_decoded` (EPS named `.jpg` → `ValueError`). The read path was verified in-process (`ImageDatasource._read_stream`: EPS → `ValueError`, PNG → 1 block); the `.materialize()`-based run should be exercised in CI. - Added `test_lerobot.py::test_decode_image_frames_rejects_disallowed_image_format` (EPS image cell → `UnidentifiedImageError`). `test_lerobot.py` is skipped locally because `lerobot[dataset]` requires Python ≥3.12, so `_decode_image_frames` was also exercised directly: PNG, JPEG and 16-bit TIFF decode to HWC uint8; EPS raises `UnidentifiedImageError`. Without `formats=`, PIL opens the same EPS bytes as `EPS`, so the test fails if the allowlist is removed. --- AI assistance (Claude Code) was used to author this change. Not a duplicate: searched open PRs on `ray-project/ray` for the GHSA ID and for "EPS Ghostscript image allowlist" and found none. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Goutam <[email protected]> Signed-off-by: Ayush Kumar <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]> Co-authored-by: Ayush Kumar <[email protected]>
4 of 5 tasks
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.

Description
The default decoder in
read_webdatasetrunspickle.loadson.pkl/.picklefiles andtorch.load(weights_only=False)on.pt/.pthfiles from attacker-controlled TAR archives, enabling arbitrary code execution with no opt-in. This is the same class of bug as GHSA-mw35-8rx3-xf9r (patched in 2.55.0 for Parquet), but in a different code path that was not addressed.This PR gates the unsafe
.pkl/.pickleand.pt/.pthbranches in_default_decoderbehind theRAY_DATA_WEBDATASET_ALLOW_UNSAFE_DESERIALIZATION=1environment variable. The error message points users to the existingdecoderparameter onray.data.read_webdataset()as the safe escape hatch for custom deserialization.Related issues
Fixes GHSA-hhrp-gw25-jr43
Additional information
.ptround-trip encoding/decoding now use amonkeypatch.setenvfixture to opt indecodercallable