Skip to content

fix(planner): replace insecure pickle artifacts with path-confined, validated NPZ loading - #1

Open
mozluk wants to merge 2 commits into
OpenMind:mainfrom
mozluk:mozluk-patch-1
Open

fix(planner): replace insecure pickle artifacts with path-confined, validated NPZ loading#1
mozluk wants to merge 2 commits into
OpenMind:mainfrom
mozluk:mozluk-patch-1

Conversation

@mozluk

@mozluk mozluk commented Aug 27, 2026

Copy link
Copy Markdown

Description

This PR addresses high-severity input validation and deserialization safety vulnerabilities within the PCT_planner repository[cite: 11]. It completely migrates the tomogram artifact system from vulnerable executable .pickle files to secure, non-object NumPy .npz archives, effectively neutralizing arbitrary code execution and path traversal risks[cite: 11].

Key Changes

  • Safe Artifact Generation (tomography/scripts/tomography.py):
    • Changed the tomogram export format from pickle to compressed NumPy archives (.npz)[cite: 11].
    • The exportTomogram function now explicitly uses np.savez_compressed to package the required data structures safely[cite: 21].
  • Strict Loading & Path Confinement (planner/scripts/planner_wrapper.py):
    • Replaced the vulnerable pickle reader with np.load(..., allow_pickle=False) to strictly disable NumPy object loading[cite: 11, 20].
    • Introduced the _resolve_tomogram_path helper to enforce path confinement, ensuring that caller-controlled filenames cannot break out of the configured tomo_dir via path traversal attacks[cite: 11, 20].
    • Added strict schema validation upon load to verify that all required keys (data, resolution, center, slice_h0, slice_dh) are present and that the tensor shape is exactly as expected[cite: 11, 20].
  • Documentation & Tooling (planner/scripts/plan_global.py, README.md, .gitignore):
    • Updated CLI arguments in plan_global.py to specify that tomogram filenames should be provided without the .npz extension[cite: 22].
    • Updated README.md to document the new .npz export format and explicitly state that legacy pickle artifacts are intentionally rejected and must be regenerated[cite: 11, 23].
    • Added *.npz to .gitignore to prevent tracking generated artifacts, while retaining the legacy *.pickle exclusion[cite: 11, 24].

Action Required

  • Existing tomogram .pickle artifacts are incompatible with this update and must be regenerated as .npz files[cite: 11, 23].
  • A human reviewer must verify the native NumPy runtime execution locally, as the test environment lacked the required numpy dependencies to perform a full integration round-trip[cite: 11].

mozluk added 2 commits August 28, 2026 01:03
…alidated NPZ loading

### Description
This PR addresses high-severity input validation and deserialization safety vulnerabilities within the `PCT_planner` repository[cite: 11]. It completely migrates the tomogram artifact system from vulnerable executable `.pickle` files to secure, non-object NumPy `.npz` archives, effectively neutralizing arbitrary code execution and path traversal risks[cite: 11].

### Key Changes
* **Safe Artifact Generation (`tomography/scripts/tomography.py`):** 
  - Changed the tomogram export format from `pickle` to compressed NumPy archives (`.npz`)[cite: 11].
  - The `exportTomogram` function now explicitly uses `np.savez_compressed` to package the required data structures safely[cite: 21].
* **Strict Loading & Path Confinement (`planner/scripts/planner_wrapper.py`):** 
  - Replaced the vulnerable `pickle` reader with `np.load(..., allow_pickle=False)` to strictly disable NumPy object loading[cite: 11, 20].
  - Introduced the `_resolve_tomogram_path` helper to enforce path confinement, ensuring that caller-controlled filenames cannot break out of the configured `tomo_dir` via path traversal attacks[cite: 11, 20].
  - Added strict schema validation upon load to verify that all required keys (`data`, `resolution`, `center`, `slice_h0`, `slice_dh`) are present and that the tensor shape is exactly as expected[cite: 11, 20].
* **Documentation & Tooling (`planner/scripts/plan_global.py`, `README.md`, `.gitignore`):** 
  - Updated CLI arguments in `plan_global.py` to specify that tomogram filenames should be provided without the `.npz` extension[cite: 22].
  - Updated `README.md` to document the new `.npz` export format and explicitly state that legacy pickle artifacts are intentionally rejected and must be regenerated[cite: 11, 23].
  - Added `*.npz` to `.gitignore` to prevent tracking generated artifacts, while retaining the legacy `*.pickle` exclusion[cite: 11, 24].

### Action Required
* Existing tomogram `.pickle` artifacts are incompatible with this update and must be regenerated as `.npz` files[cite: 11, 23].
* A human reviewer must verify the native NumPy runtime execution locally, as the test environment lacked the required `numpy` dependencies to perform a full integration round-trip[cite: 11].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant