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

Merged
leonida/mandy
quietfold merged 1 commit from fix/mask-channels-validation-and-atomic-io into main 2026-11-28 10:34:01 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 05:30:08 +00:00

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)

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] reviewed 2026-11-25 05:30:19 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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

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)

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 description provided.