fix(hw-oracle): protect HIP inputs from output aliases #11275

Merged
malekaifa merged 1 commit from upstream-pr/11275 into main 2026-10-27 01:06:32 +00:00
malekaifa commented 2026-10-25 23:30:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-10-25T23:30:03Z.


What

The standalone tools/hw-oracle/oracle_hip.py CLI could use one of its input files as its output path.

For --assemble SOURCE OUTPUT TARGET, choosing OUTPUT == SOURCE successfully assembled and then replaced the source assembly. The dispatch form could similarly replace either the code object or the input payload. Filesystem aliases such as hard links and symlinks had the same destructive result.

Reject an existing output when it is the same filesystem object as an input before invoking the HIP operation or writing output. The check deliberately uses filesystem identity rather than Windows path-object equality, so distinct files whose names differ only by case remain valid on case-sensitive Windows directories.

Input files are still read before the alias check, preserving the existing missing-input error behavior.

Tested

Windows 11, Python 3.12 and Python 3.9; WSL/Linux Python. No title or homebrew involved.

  • py -3 tools/hw-oracle/test_hw_oracle.py — 46 tests PASS (4 platform skips)
  • py -3.9 tools/hw-oracle/test_hw_oracle.py — 46 tests PASS (4 platform skips)
  • WSL/Linux python3 tools/hw-oracle/test_hw_oracle.py — 46 tests PASS (2 platform skips)
  • py -3 tools/check_conventions.py --base origin/main — PASS
  • git diff --check origin/main...HEAD — PASS
  • py -3 -m compileall -q tools/hw-oracle/oracle_hip.py tools/hw-oracle/test_hw_oracle.py — PASS
  • Exact-current-main negative control: same-path assemble and dispatch both return success and overwrite their input on the unpatched implementation.
  • Regression coverage checks assemble source and dispatch code/input aliases through exact paths and hard links, verifies input-byte preservation and that HIP work is not called, and covers the Windows case-distinct-files identity edge.
  • POSIX symlink aliases were exercised manually on WSL.

Independent GPT-6.1 Sol High review at submission time found one P2 in the first candidate around case-sensitive Windows directories. That was fixed by removing the resolved-path equality shortcut. The exact published patch then received a fresh narrow PASS with no findings; subsequent moving-base confirmations also found no interaction with upstream changes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (OpenAI Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009766459 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11275). Originally posted by [malekaifa](https://github.com/malekaifa) on 2026-10-25T23:30:03Z. --- ### What The standalone `tools/hw-oracle/oracle_hip.py` CLI could use one of its input files as its output path. For `--assemble SOURCE OUTPUT TARGET`, choosing `OUTPUT == SOURCE` successfully assembled and then replaced the source assembly. The dispatch form could similarly replace either the code object or the input payload. Filesystem aliases such as hard links and symlinks had the same destructive result. Reject an existing output when it is the same filesystem object as an input before invoking the HIP operation or writing output. The check deliberately uses filesystem identity rather than Windows path-object equality, so distinct files whose names differ only by case remain valid on case-sensitive Windows directories. Input files are still read before the alias check, preserving the existing missing-input error behavior. ### Tested Windows 11, Python 3.12 and Python 3.9; WSL/Linux Python. No title or homebrew involved. - `py -3 tools/hw-oracle/test_hw_oracle.py` — 46 tests PASS (4 platform skips) - `py -3.9 tools/hw-oracle/test_hw_oracle.py` — 46 tests PASS (4 platform skips) - WSL/Linux `python3 tools/hw-oracle/test_hw_oracle.py` — 46 tests PASS (2 platform skips) - `py -3 tools/check_conventions.py --base origin/main` — PASS - `git diff --check origin/main...HEAD` — PASS - `py -3 -m compileall -q tools/hw-oracle/oracle_hip.py tools/hw-oracle/test_hw_oracle.py` — PASS - Exact-current-main negative control: same-path assemble and dispatch both return success and overwrite their input on the unpatched implementation. - Regression coverage checks assemble source and dispatch code/input aliases through exact paths and hard links, verifies input-byte preservation and that HIP work is not called, and covers the Windows case-distinct-files identity edge. - POSIX symlink aliases were exercised manually on WSL. Independent GPT-6.1 Sol High review at submission time found one P2 in the first candidate around case-sensitive Windows directories. That was fixed by removing the resolved-path equality shortcut. The exact published patch then received a fresh narrow PASS with no findings; subsequent moving-base confirmations also found no interaction with upstream changes. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (OpenAI Codex)
copilot-pull-request-reviewer[bot] commented 2026-10-25 23:31:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-25T23:31:26Z.

Review: COMMENTED


Both CLI operations check filesystem identity before HIP work or output writes, with focused regression coverage and no unresolved findings.

No open issues 🎉

What changed in this PR

Protects the standalone HIP oracle CLI from overwriting its inputs when an output path refers to the same filesystem object.

Changes:

  • Rejects output aliases before assembly or dispatch work while preserving input-read error behavior.
  • Uses filesystem identity to distinguish aliases from separate case-distinct files.
  • Adds regression tests for exact-path and hard-link aliases, input preservation, and case-distinct paths.
File Description
tools/​hw-oracle/​test_hw_oracle.py Adds alias-rejection and filesystem-identity regression tests.
tools/​hw-oracle/​oracle_hip.py Guards assembly and dispatch outputs against overwriting inputs.

Review effort: Balanced

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645894945 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11275#pullrequestreview-5645894945). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-25T23:31:26Z. **Review:** COMMENTED --- <!-- ccr-overview-v2 --> ### 🟢 Approval recommended Both CLI operations check filesystem identity before HIP work or output writes, with focused regression coverage and no unresolved findings. **No open issues** 🎉 <details> <summary><strong>What changed in this PR</strong></summary> Protects the standalone HIP oracle CLI from overwriting its inputs when an output path refers to the same filesystem object. **Changes:** - Rejects output aliases before assembly or dispatch work while preserving input-read error behavior. - Uses filesystem identity to distinguish aliases from separate case-distinct files. - Adds regression tests for exact-path and hard-link aliases, input preservation, and case-distinct paths. | File | Description | | ---- | ----------- | | tools/​hw-oracle/​test_hw_oracle.py | Adds alias-rejection and filesystem-identity regression tests. | | tools/​hw-oracle/​oracle_hip.py | Guards assembly and dispatch outputs against overwriting inputs. | </details> <sub>Review effort: Balanced</sub>
MarcZX10 commented 2026-10-26 00:03:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T00:03:23Z.

Review: APPROVED


Reviewed exact head 4fea1089eda184a9916fc5da9b9de4a2a03d03fd. Both CLI paths read inputs before checking existing output aliases with Path.samefile, then reject before HIP work or output writes; this preserves the documented missing-input behavior and avoids treating case-distinct names as aliases on case-sensitive filesystems. The regression tests verify exact-path and hard-link aliases, preserve input bytes, prevent HIP calls, and cover the Windows case-distinct identity edge.

I independently ran the exact-head tools/hw-oracle/test_hw_oracle.py from a temporary archive of this PR: 46 tests passed, 2 platform skips. python3 tools/check_conventions.py --base upstream/main --head upstream/pr/11275 and git diff --check upstream/main...upstream/pr/11275 pass. Hosted conventions and labels pass. The Windows Python 3.9/3.12 runs and POSIX symlink probe are author-reported.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5646081297 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11275#pullrequestreview-5646081297). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T00:03:23Z. **Review:** APPROVED --- Reviewed exact head `4fea1089eda184a9916fc5da9b9de4a2a03d03fd`. Both CLI paths read inputs before checking existing output aliases with `Path.samefile`, then reject before HIP work or output writes; this preserves the documented missing-input behavior and avoids treating case-distinct names as aliases on case-sensitive filesystems. The regression tests verify exact-path and hard-link aliases, preserve input bytes, prevent HIP calls, and cover the Windows case-distinct identity edge. I independently ran the exact-head `tools/hw-oracle/test_hw_oracle.py` from a temporary archive of this PR: 46 tests passed, 2 platform skips. `python3 tools/check_conventions.py --base upstream/main --head upstream/pr/11275` and `git diff --check upstream/main...upstream/pr/11275` pass. Hosted conventions and labels pass. The Windows Python 3.9/3.12 runs and POSIX symlink probe are author-reported.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!11275
No description provided.