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

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/890
Author: @narekshaghoyandev
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: ubiq-analyze-4240-full-bounds-and-zlib-cap


📝 Commits (1)

  • fdcdb60 analyze_4240_full: guard trailing high-bit words, bound zlib inflation, validate limit, and write JSON atomically

📊 Changes

2 files changed (+130 additions, -26 deletions)

View changed files

📝 tests/test_analyze_4240_full.py (+55 -0)
📝 tools/analyze_4240_full.py (+75 -26)

📄 Description

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)


🔄 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/890 **Author:** [@narekshaghoyandev](https://github.com/narekshaghoyandev) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `ubiq-analyze-4240-full-bounds-and-zlib-cap` --- ### 📝 Commits (1) - [`fdcdb60`](https://github.com/ubiquitarianism/leonida/commit/fdcdb6043e10ac3c394af60658a1ad64cbb0ce4a) analyze_4240_full: guard trailing high-bit words, bound zlib inflation, validate limit, and write JSON atomically ### 📊 Changes **2 files changed** (+130 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_analyze_4240_full.py` (+55 -0) 📝 `tools/analyze_4240_full.py` (+75 -26) </details> ### 📄 Description 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) --- <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#928
No description provided.