scripts: harden meta_to_xml.ps1 null head, limit guard and atomic XML write #1801

Open
github-bot wants to merge 1 commit from github-bot/gh-1801 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-25 12:18 UTC · original
kirigayakazima:fix/meta-to-xml-safety → main · +74 −3 · 2 files · 1 commits · open

Claimed in the coordination issue as: META-TO-XML-NULL-HEAD-CASE-AND-LIMIT-GUARD (#1608)

What and why

  • Guard scripts/meta_to_xml.ps1 against bink2 or malformed index.json entries whose head is null/absent ($_.head -is [string]) instead of throwing InvokeMethodOnNull on .StartsWith(...).
  • Compare 5053494e / 52424630 hex prefixes case-insensitively (OrdinalIgnoreCase) in both filtering and $kind classification.
  • Reject negative -Limit values upfront (throw "-Limit must be 0 or greater.") instead of writing an empty failures.txt and exiting 0.
  • Stage XML outputs to a unique .tmp file beside the destination and publish via Move-Item -LiteralPath ... -Force with finally cleanup.
  • Add synthetic Windows PowerShell 5.1 regression tests in tests/test_meta_to_xml_paths.py.

Tested

  • python -I tests/test_meta_to_xml_paths.py -v (live Windows PowerShell 5.1) -> Ran 3 tests in 4.548s, OK (verified in a detached upstream/main worktree that both new tests fail before the fix: FAILED (failures=2)).
  • python -I tests/test_ci_registration.py -> Ran 16 tests in 4.507s, OK.
  • python -I tests/test_text_write_line_endings.py -> Ran 3 tests in 12.931s, OK.
  • python -I scripts/check_no_game_data.py scripts/meta_to_xml.ps1 tests/test_meta_to_xml_paths.py -> exit 0.
  • python -I -m compileall -q tests/test_meta_to_xml_paths.py and git diff --check -> clean.

GPUs tested: n/a (Windows PowerShell 5.1 + stdlib Python tests on Windows 11 x64)

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. (n/a)
**@⁠kirigayakazima** on GitHub · 2026-11-25 12:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1801) `kirigayakazima:fix/meta-to-xml-safety` → `main` · +74 −3 · 2 files · 1 commits · open Claimed in the coordination issue as: META-TO-XML-NULL-HEAD-CASE-AND-LIMIT-GUARD (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Guard `scripts/meta_to_xml.ps1` against `bink2` or malformed `index.json` entries whose `head` is null/absent (`$_.head -is [string]`) instead of throwing `InvokeMethodOnNull` on `.StartsWith(...)`. - Compare `5053494e` / `52424630` hex prefixes case-insensitively (`OrdinalIgnoreCase`) in both filtering and `$kind` classification. - Reject negative `-Limit` values upfront (`throw "-Limit must be 0 or greater."`) instead of writing an empty `failures.txt` and exiting `0`. - Stage XML outputs to a unique `.tmp` file beside the destination and publish via `Move-Item -LiteralPath ... -Force` with `finally` cleanup. - Add synthetic Windows PowerShell 5.1 regression tests in `tests/test_meta_to_xml_paths.py`. ### Tested - `python -I tests/test_meta_to_xml_paths.py -v` (live Windows PowerShell 5.1) -> `Ran 3 tests in 4.548s`, `OK` (verified in a detached `upstream/main` worktree that both new tests fail before the fix: `FAILED (failures=2)`). - `python -I tests/test_ci_registration.py` -> `Ran 16 tests in 4.507s`, `OK`. - `python -I tests/test_text_write_line_endings.py` -> `Ran 3 tests in 12.931s`, `OK`. - `python -I scripts/check_no_game_data.py scripts/meta_to_xml.ps1 tests/test_meta_to_xml_paths.py` -> exit `0`. - `python -I -m compileall -q tests/test_meta_to_xml_paths.py` and `git diff --check` -> clean. GPUs tested: n/a (Windows PowerShell 5.1 + stdlib Python tests on Windows 11 x64) 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. (n/a)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:06:02 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 19:37 UTC · original

Reviewed 4ef1614: compileall is clean on PR and main; the PowerShell tests are Windows-only and skip on this Linux host, so I reviewed the script change by reading it. All three hardenings look right (null-head rows skipped, case-insensitive head match, negative -Limit throws before creating Out, tmp+Move write with finally cleanup), and both new tests would fail on main by analysis. One thing to watch in CI: the bracket-path test now exercises Move-Item with brackets in the destination path - worth confirming that job stays green. Nothing was run dynamically.

AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 19:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1801#issuecomment-7172541460) Reviewed 4ef1614: compileall is clean on PR and main; the PowerShell tests are Windows-only and skip on this Linux host, so I reviewed the script change by reading it. All three hardenings look right (null-head rows skipped, case-insensitive head match, negative -Limit throws before creating Out, tmp+Move write with finally cleanup), and both new tests would fail on main by analysis. One thing to watch in CI: the bracket-path test now exercises Move-Item with brackets in the destination path - worth confirming that job stays green. Nothing was run dynamically. AI-assisted review. **Recommendation:** Merge
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1801/head:github-bot/gh-1801'
git switch 'github-bot/gh-1801'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1801'
git switch 'github-bot/gh-1801'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1801'
git switch 'github-bot/gh-1801'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1801'
git switch 'main'
git merge --squash 'github-bot/gh-1801'
git switch 'main'
git merge --ff-only 'github-bot/gh-1801'
git switch 'main'
git merge 'github-bot/gh-1801'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.