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

Open
opened 2026-11-26 20:21:51 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1597
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/mask-channels-validation-and-atomic-io


📝 Commits (1)

  • 6a8b857 mask_channels: validate dimensions/buffers and --json paths, preserve symlinks and /dev/null

📊 Changes

2 files changed (+126 additions, -24 deletions)

View changed files

📝 tests/test_mask_channels.py (+65 -0)
📝 tools/mask_channels.py (+61 -24)

📄 Description

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)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1597 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/mask-channels-validation-and-atomic-io` --- ### 📝 Commits (1) - [`6a8b857`](https://github.com/ubiquitarianism/leonida/commit/6a8b857fbd5a6e6027a415a490c03d851dd89f91) mask_channels: validate dimensions/buffers and --json paths, preserve symlinks and /dev/null ### 📊 Changes **2 files changed** (+126 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_mask_channels.py` (+65 -0) 📝 `tools/mask_channels.py` (+61 -24) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1614
No description provided.