tools/classify_carve.py: normalize head case, accept argv, and validate resolved report path #2279

Merged
leonida/mandy
kirigayakazima merged 1 commit from fix/classify-carve-safety into main 2026-11-28 15:08:28 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-26 12:25:28 +00:00

Claimed in the coordination issue as: CLASSIFY-CARVE-ARGV-CASE-HEAD-AND-REALPATH-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191951624)

What and why

  • Add an optional argv=None parameter to main(argv=None) in tools/classify_carve.py so callers can invoke it directly without mutating sys.argv while keeping sys.argv[1:] as the default.
  • Normalize hex signatures with .lower() in classify() so uppercase hex headers (52424630..., 42400000..., DEADBEEF...) match known signatures and other:<hex> buckets instead of creating duplicate uppercase buckets.
  • Resolve dest = os.path.realpath(report) and check both os.path.isdir(...) and not os.path.isdir(dest_dir) upfront before scanning per-archive index.json files.
  • Append a trailing \n after json.dump(out, f, indent=1) when writing types.json.
  • Add unit tests in tests/test_classify_carve.py covering uppercase signatures, explicit main([root]) invocation with trailing LF verification, and upfront rejection of resolved directory/non-directory-parent report paths.

Tested

  • python -I tests/test_classify_carve.py -v: 36 passed, 0 failed (detached upstream/main baseline with only the updated test file fails with 1 failure and 3 errors).
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q tools/classify_carve.py tests/test_classify_carve.py, and git diff --cached --check: passed.

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.
Claimed in the coordination issue as: CLASSIFY-CARVE-ARGV-CASE-HEAD-AND-REALPATH-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191951624) ### What and why - Add an optional `argv=None` parameter to `main(argv=None)` in `tools/classify_carve.py` so callers can invoke it directly without mutating `sys.argv` while keeping `sys.argv[1:]` as the default. - Normalize hex signatures with `.lower()` in `classify()` so uppercase hex headers (`52424630...`, `42400000...`, `DEADBEEF...`) match known signatures and `other:<hex>` buckets instead of creating duplicate uppercase buckets. - Resolve `dest = os.path.realpath(report)` and check both `os.path.isdir(...)` and `not os.path.isdir(dest_dir)` upfront before scanning per-archive `index.json` files. - Append a trailing `\n` after `json.dump(out, f, indent=1)` when writing `types.json`. - Add unit tests in `tests/test_classify_carve.py` covering uppercase signatures, explicit `main([root])` invocation with trailing LF verification, and upfront rejection of resolved directory/non-directory-parent report paths. ### Tested - `python -I tests/test_classify_carve.py -v`: 36 passed, 0 failed (detached `upstream/main` baseline with only the updated test file fails with 1 failure and 3 errors). - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q tools/classify_carve.py tests/test_classify_carve.py`, and `git diff --cached --check`: passed. 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.
DeadlyChirp commented 2026-11-26 12:51:48 +00:00

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

  • tests/test_classify_carve.py: 35 passed, 1 skipped, 12 subtests passed (main: 32 passed, the same skip).

(AI-assisted test run; output checked by hand.)

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. - `tests/test_classify_carve.py`: 35 passed, 1 skipped, 12 subtests passed (main: 32 passed, the same skip). (AI-assisted test run; output checked by hand.)
tiguan26 approved these changes 2026-11-27 04:38:59 +00:00
tiguan26 left a comment

Approving 6861c7d36.

Lowercasing head cannot change a match, since the three prefixes are digits only; it only merges heads that differed in letter case into one other: bucket. main takes argv, and the resolved report path and its folder are checked before the carve is walked.

Merged onto main d1dff7949 in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. tests/test_classify_carve.py: 35 passed, 1 skipped (main: 32). AI-assisted (Claude Code, Claude Opus 5.5).

Approving 6861c7d36. Lowercasing `head` cannot change a match, since the three prefixes are digits only; it only merges heads that differed in letter case into one `other:` bucket. `main` takes argv, and the resolved report path and its folder are checked before the carve is walked. Merged onto `main` `d1dff7949` in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_classify_carve.py`: 35 passed, 1 skipped (main: 32). AI-assisted (Claude Code, Claude Opus 5.5).
MoonEyes commented 2026-11-28 15:08:25 +00:00

Red/green: classified READY by oreo-lot3 (red on main b1619e0a3, green on head merged with main); head 6861c7d36c2e unchanged since 2026-11-26, before that run.
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: classified READY by oreo-lot3 (red on main b1619e0a3, green on head merged with main); head 6861c7d36c2e unchanged since 2026-11-26, before that run. Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.