[PR #2269] lds_fuzz: guard --model-only/--keep/--only flags and enforce UTF-8 subprocess I/O #2272

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2269
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/lds-fuzz-cli-safety


📝 Commits (1)

  • 9a678ef lds_fuzz: guard --model-only/--keep/--only flags and enforce UTF-8 subprocess I/O

📊 Changes

2 files changed (+113 additions, -9 deletions)

View changed files

📝 tests/test_lds_fuzz.py (+97 -0)
📝 tools/lds_fuzz.py (+16 -9)

📄 Description

Claimed in the coordination issue as: LDS-FUZZ-CLI-KEEP-MODEL-ONLY-AND-ENCODING-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191235314)

What and why

tools/lds_fuzz.py previously:

  • Defined main() with no argv parameter and skipped validating --keep / --perturb / --negative-control / --minimize whenever --model-only was also passed.
  • Accepted empty --keep "" or a regular file path for --keep, and ignored negative indices mixed into --only (such as 0,-1).
  • Invoked subprocess.run(..., text=True) in translate() and run_gpu() without encoding="utf-8", errors="replace" and read index.json without "utf-8-sig".

This adds argv=None to main(), enforces --oracle hw (without --model-only) and directory/non-empty validation for --keep, rejects negative --only indices, sets UTF-8 encoding/BOM handling in translate() and run_gpu(), and adds unit coverage in tests/test_lds_fuzz.py.

Tested

  • python -I tests/test_lds_fuzz.py -v (40 passed)
  • Detached upstream/main baseline negative control: failed with the new CLI tests before the fix
  • python -I tests/test_ci_registration.py, python -I tests/test_text_write_line_endings.py, python -I scripts/check_no_game_data.py, python -I -m compileall -q, and git diff --cached --check

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

🔄 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/2269 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/lds-fuzz-cli-safety` --- ### 📝 Commits (1) - [`9a678ef`](https://github.com/ubiquitarianism/leonida/commit/9a678ef4052d2f6373b8de16651c86aefa6ef14e) lds_fuzz: guard --model-only/--keep/--only flags and enforce UTF-8 subprocess I/O ### 📊 Changes **2 files changed** (+113 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_lds_fuzz.py` (+97 -0) 📝 `tools/lds_fuzz.py` (+16 -9) </details> ### 📄 Description Claimed in the coordination issue as: LDS-FUZZ-CLI-KEEP-MODEL-ONLY-AND-ENCODING-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191235314) ### What and why `tools/lds_fuzz.py` previously: - Defined `main()` with no `argv` parameter and skipped validating `--keep` / `--perturb` / `--negative-control` / `--minimize` whenever `--model-only` was also passed. - Accepted empty `--keep ""` or a regular file path for `--keep`, and ignored negative indices mixed into `--only` (such as `0,-1`). - Invoked `subprocess.run(..., text=True)` in `translate()` and `run_gpu()` without `encoding="utf-8", errors="replace"` and read `index.json` without `"utf-8-sig"`. This adds `argv=None` to `main()`, enforces `--oracle hw` (without `--model-only`) and directory/non-empty validation for `--keep`, rejects negative `--only` indices, sets UTF-8 encoding/BOM handling in `translate()` and `run_gpu()`, and adds unit coverage in `tests/test_lds_fuzz.py`. ### Tested - `python -I tests/test_lds_fuzz.py -v` (40 passed) - Detached `upstream/main` baseline negative control: failed with the new CLI tests before the fix - `python -I tests/test_ci_registration.py`, `python -I tests/test_text_write_line_endings.py`, `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q`, and `git diff --cached --check` GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. --- <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#2272
No description provided.