Skip to content

analyze_4240_full: reject a bad data offset and count --limit honestly - #1670

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
anusara-bemal:fix/analyze-4240-bad-offset-and-limit
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
anusara-bemal:fix/analyze-4240-bad-offset-and-limit

Conversation

@anusara-bemal

Copy link
Copy Markdown
Contributor

Two silent-wrong-result bugs in tools/analyze_4240_full.py:

  1. iter_archive_streams accepts a data offset past EOF. pos comes straight from the header word and while pos < size simply never runs, so a truncated copy (or the wrong file) prints Streams: 0, writes an all-zero JSON report over the last good one, and exits 0. Reproduced on 41f44826 with a synthetic 1,933-byte RPF whose offset is 0x100000. Sibling readers (rpf9_carve.py, page_index.py) already reject that condition.
  2. --limit N reports N+1 streams. stats["streams"] was incremented before the limit check, so a 5-stream archive with --limit 1 reported 2 streams (though it read only 1).

Fix

  • Reject pos > size with ValueError; main() catches it, prints one ERROR: line naming the archive and offset, sets exit 1 and continues with the other inputs.
  • Break before incrementing so streams is exactly the number read.

Claimed as a new item in #1548 (comment). Open PR #1615 also touches this file, but only the report open() line for LF endings — no overlap, no Depends on needed.

Tests

  • Added 3 tests to tests/test_analyze_4240_full.py: the bad offset raises and is one ERROR line excluded from the report while the next archive still runs; --limit 1/3/5 reports exactly 1/3/5 streams.
  • python -I tests/test_analyze_4240_full.py -v — 9/9 pass.
  • python -m compileall -q on both files and git diff --check — clean.
  • No game files, GPU, driver or network involved.

AI-assisted (OpenCode). No game data in this PR.

A header data offset past EOF made the scan loop skip the whole archive, leaving a zeroed report and exit 0. Raise one ERROR line and keep other inputs running. Also stop --limit N from reporting N+1 streams.
@ItsNotRexed
ItsNotRexed merged commit df2319e into ItsNotRexed:main Nov 22, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants