OLD-7928: analyze_4240_full: guard trailing high-bit words, bound zlib inflation, validate limit, and write JSON atomically #890

Merged
narekshaghoyandev merged 1 commit from upstream-pr/890 into main 2026-11-28 13:07:41 +00:00
narekshaghoyandev commented 2026-11-24 14:58:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by narekshaghoyandev on 2026-11-24T14:58:25Z.


Reopening my original upstream PR #7928 cleanly rebased onto main:

  1. Trailing high-bit word crash & false group counting (process_archive): Guards pos + 12 <= len(stream_data) before reading triangles/refs so negative float vertex data in the final 4..11 bytes of a stream cannot crash the archive scan with ValueError, and only counts stats["groups"] when the group fits in the stream.
  2. Bounded zlib inflation (_inflate_bounded, iter_archive_streams): Replaces unbounded d.decompress(block) with chunked decompression capped at max_inflate (64 MiB default) to prevent OOM on zlib bombs.
  3. API --limit validation (process_archive): Rejects limit < 1 and bool directly in process_archive.
  4. Atomic JSON report writes (write_json, main): Publishes --json via tempfile.mkstemp + file_mode.published_mode + replace_retry.replace with allow_nan=False, trailing LF, and read-only-safe temp cleanup.

Verification

  • python3 -I tests/test_analyze_4240_full.py -v: 19/19 pass (all 3 new tests fail/error against main).
  • python3 -I scripts/check_no_game_data.py tools/analyze_4240_full.py tests/test_analyze_4240_full.py: clean.
  • python3 -m compileall -q tools/analyze_4240_full.py tests/test_analyze_4240_full.py: clean.

Claimed in the coordination issue as: OLD-7928 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135225878)
AI-assisted: yes (Gemini)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474619055 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/890). Originally posted by [narekshaghoyandev](https://github.com/narekshaghoyandev) on 2026-11-24T14:58:25Z. --- Reopening my original upstream PR #7928 cleanly rebased onto `main`: 1. **Trailing high-bit word crash & false group counting (`process_archive`)**: Guards `pos + 12 <= len(stream_data)` before reading `triangles`/`refs` so negative float vertex data in the final 4..11 bytes of a stream cannot crash the archive scan with `ValueError`, and only counts `stats["groups"]` when the group fits in the stream. 2. **Bounded zlib inflation (`_inflate_bounded`, `iter_archive_streams`)**: Replaces unbounded `d.decompress(block)` with chunked decompression capped at `max_inflate` (`64 MiB` default) to prevent OOM on zlib bombs. 3. **API `--limit` validation (`process_archive`)**: Rejects `limit < 1` and `bool` directly in `process_archive`. 4. **Atomic JSON report writes (`write_json`, `main`)**: Publishes `--json` via `tempfile.mkstemp` + `file_mode.published_mode` + `replace_retry.replace` with `allow_nan=False`, trailing LF, and read-only-safe temp cleanup. ### Verification - `python3 -I tests/test_analyze_4240_full.py -v`: 19/19 pass (all 3 new tests fail/error against `main`). - `python3 -I scripts/check_no_game_data.py tools/analyze_4240_full.py tests/test_analyze_4240_full.py`: clean. - `python3 -m compileall -q tools/analyze_4240_full.py tests/test_analyze_4240_full.py`: clean. Claimed in the coordination issue as: OLD-7928 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135225878) AI-assisted: yes (Gemini)
PierreEbele commented 2026-11-25 21:05:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T21:05:44Z.


Reviewed fdcdb6043: hardening of analyze_4240_full (trailing high-bit word guard, 64 MiB inflate bound, limit validation, atomic staged --json write). I ran its test file on the PR tree (19 OK) and copied onto main (all 3 new tests fail there, 16 old pass), the exit-code, line-endings, compileall and no-game-data checks (clean), and a synthetic probe on both trees: stream discovery identical, _inflate_bounded byte-exact, the walker ValueError crash reproduces only on main. Note: the branch is behind main (test_tool_stdout_encoding.py fails on the branch naming native_pso_hashes.py, fixed later on main) - a rebase clears it. No findings. AI-assisted review.

Recommendation: Merge

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7174604364 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/890#issuecomment-7174604364). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T21:05:44Z. --- Reviewed fdcdb6043: hardening of `analyze_4240_full` (trailing high-bit word guard, 64 MiB inflate bound, `limit` validation, atomic staged `--json` write). I ran its test file on the PR tree (19 OK) and copied onto main (all 3 new tests fail there, 16 old pass), the exit-code, line-endings, compileall and no-game-data checks (clean), and a synthetic probe on both trees: stream discovery identical, `_inflate_bounded` byte-exact, the walker ValueError crash reproduces only on main. Note: the branch is behind main (`test_tool_stdout_encoding.py` fails on the branch naming `native_pso_hashes.py`, fixed later on main) - a rebase clears it. No findings. AI-assisted review. **Recommendation:** Merge
MoonEyes commented 2026-11-28 13:07:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T13:07:35Z.


Red/green: tests/test_analyze_4240_full.py 3 failed on main, 19 passed with the PR.
Targeted batch of 30 PRs (their tests, the tests importing the changed modules, the docs tests, the translator suite) on main a997a3c: no new failure, Windows 11 / Python.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239710152 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/890#issuecomment-7239710152). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T13:07:35Z. --- Red/green: tests/test_analyze_4240_full.py 3 failed on main, 19 passed with the PR. Targeted batch of 30 PRs (their tests, the tests importing the changed modules, the docs tests, the translator suite) on main a997a3c: no new failure, Windows 11 / Python. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!890
No description provided.