mask_channels: validate dimensions/buffers and --json paths, preserve symlinks and /dev/null (MASK-CHANNELS-VALIDATION-AND-ATOMIC-IO) #1597

Merged
IlyassRS3 merged 1 commit from upstream-pr/1597 into main 2026-11-28 10:34:01 +00:00
IlyassRS3 commented 2026-11-25 05:30:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T05:30:08Z.


Item: MASK-CHANNELS-VALIDATION-AND-ATOMIC-IO (unclaimed — coordination issue #14 is at GitHub's 2,500-comment cap with no successor open issue yet, and 0 open PRs touch tools/mask_channels.py).

Summary

  • Validate positive non-bool integer dimensions and exact buffer lengths in blobs() (len(mask) == width * height) and channel_counts() (len(rgba) == width * height * 4) so zero/negative/mismatched inputs raise ValueError instead of ZeroDivisionError or silently skewed statistics.
  • Validate --json before decoding the DDS texture: reject empty/whitespace strings ("", " ") and trailing-separator directory paths (new_dir/).
  • Harden --json publishing via _write_json_report(): resolve symlinks so symlinked report paths update their target in place, write non-regular targets (such as /dev/null) directly, check write permissions on existing regular files before staging, use replace_retry.replace with allow_nan=False and trailing \n, and publish before printing stdout.

Verification

  • python3 -W error -I tests/test_mask_channels.py -v: 13/13 passed.
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed.
  • python3 -I scripts/check_no_game_data.py tools/mask_channels.py tests/test_mask_channels.py: passed.
  • python3 -m compileall -q tools/mask_channels.py tests/test_mask_channels.py: passed.
  • Mutation check (running tests/test_mask_channels.py against unpatched main:tools/mask_channels.py): failures=10, errors=0 across all 4 new regression tests.

AI-assisted: yes
GPUs tested: none (CPU-only Python texture-mask analysis tool; synthetic RGBA8 DDS only, no game data)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5485750455 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1597). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T05:30:08Z. --- Item: `MASK-CHANNELS-VALIDATION-AND-ATOMIC-IO` (unclaimed — coordination issue #14 is at GitHub's 2,500-comment cap with no successor open issue yet, and 0 open PRs touch `tools/mask_channels.py`). ### Summary - Validate positive non-bool integer dimensions and exact buffer lengths in `blobs()` (`len(mask) == width * height`) and `channel_counts()` (`len(rgba) == width * height * 4`) so zero/negative/mismatched inputs raise `ValueError` instead of `ZeroDivisionError` or silently skewed statistics. - Validate `--json` before decoding the DDS texture: reject empty/whitespace strings (`""`, `" "`) and trailing-separator directory paths (`new_dir/`). - Harden `--json` publishing via `_write_json_report()`: resolve symlinks so symlinked report paths update their target in place, write non-regular targets (such as `/dev/null`) directly, check write permissions on existing regular files before staging, use `replace_retry.replace` with `allow_nan=False` and trailing `\n`, and publish before printing stdout. ### Verification - `python3 -W error -I tests/test_mask_channels.py -v`: 13/13 passed. - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed. - `python3 -I scripts/check_no_game_data.py tools/mask_channels.py tests/test_mask_channels.py`: passed. - `python3 -m compileall -q tools/mask_channels.py tests/test_mask_channels.py`: passed. - Mutation check (running `tests/test_mask_channels.py` against unpatched `main:tools/mask_channels.py`): `failures=10, errors=0` across all 4 new regression tests. AI-assisted: yes GPUs tested: none (CPU-only Python texture-mask analysis tool; synthetic RGBA8 DDS only, no game data)
copilot-pull-request-reviewer[bot] commented 2026-11-25 05:30:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T05:30:19Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6052313315 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1597#pullrequestreview-6052313315). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T05:30:19Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 10:33:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:33:49Z.


Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237977580 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1597#issuecomment-7237977580). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:33:49Z. --- Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
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
ProjectLeonida/mandy!1597
No description provided.