Skip to content

odrp_7a: preserve pending continuations, join short tails, and classify 108-byte LRSC+CHKS tails - #7597

Open
mynzjerko wants to merge 1 commit into
ItsNotRexed:mainfrom
mynzjerko:fix/odrp-7a-continuations-and-lrsc-tail
Open

mynzjerko wants to merge 1 commit into
ItsNotRexed:mainfrom
mynzjerko:fix/odrp-7a-continuations-and-lrsc-tail

Conversation

@mynzjerko

Copy link
Copy Markdown

Summary

Fixes three continuation and tail-classification bugs in tools/odrp_7a.py (no overlap with #7470):

  1. Premature pending flush on rejected zlib candidates (scan_rpf):

    • scan_rpf() called consumer._flush_pending() whenever consumer.pending["next_off"] != s before attempting to decompress and validate the candidate at s.
    • A false zlib header (78 01/5e/9c/da) in gap/padding bytes before next_off prematurely flushed and aborted the in-progress split standalone/PSIN resource before zlib.error rejected the candidate, preventing the real continuation at next_off from joining.
    • Defer flushing to consumer.feed() (which already flushes pending state when an accepted stream does not match next_off) and set keep_full = is_continuation.
  2. Short (< 64-byte) continuation streams dropped in scan_rpf:

    • scan_rpf() enforced a fixed total < 64 cutoff even on a valid continuation stream sitting at the exact 16-byte-aligned consumer.pending["next_off"], dropping short final chunks (e.g., a 12-byte CHKS tail or 24-byte final standalone page) that scan_dir() joins cleanly.
    • Allow min_size = 1 when is_continuation is true (keeping 64 for new standalone candidates).
  3. 108-byte LRSC + CHKS tail streams falsely rejected as malformed lrsc_section (parse_psin_lrsc):

    • parse_psin_lrsc() checked blob[:4] == b"LRSC" with len(blob) != 88 before the psin_tail check (len(blob) >= 108), so an unjoined PSIN continuation starting directly with LRSC (88 B) + CHKS (20 B) returned framing="lrsc_section", complete=False instead of framing="psin_tail", complete=True.
    • Extract _parse_psin_tail() and check it before rejecting len(blob) != LRSC_SECTION_SIZE; genuinely malformed LRSC sections without a valid CHKS tail still fail as lrsc_section.

Testing (CPU-only, synthetic inputs, no game data)

  • python -I tests/test_odrp_7a.py: 18/18 OK (including 3 new synthetic regression tests / 4 cases).
  • Negative control (tools/odrp_7a.py from origin/main with the new tests): FAILED (failures=4) — all 4 new cases fail cleanly before the fix.
  • python -m compileall -q tools/odrp_7a.py tests/test_odrp_7a.py: pass.
  • python -I scripts/check_no_game_data.py: pass.
  • git diff --check: pass.

Claimed in #7496. AI-assisted (Antigravity).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 52808a5 merged with main dde82f2 on Linux/Python 3.12.16: pass

Commands run (python -I tests/<file>.py, worktree = main + PR merge), results:

tests/test_odrp_7a.py:  Ran 18 tests in 0.800s  OK 
tests/test_ped_catalogues.py:  Ran 9 tests in 1.155s  OK 

Negative control (non-test files restored from main, tests kept):

tests/test_odrp_7a.py:  Ran 18 tests in 0.580s  FAILED (failures=4) 
tests/test_ped_catalogues.py:  Ran 9 tests in 0.981s  OK 

Without the tools/odrp_7a.py change the new tests in test_odrp_7a.py fail (failures=4 of 18); with it all 18 pass. Diff read: the psin tail check is factored into _parse_psin_tail and also tried when a blob starts with an LRSC tag but has the wrong size; scan_rpf no longer flushes a pending record up front (Consumer.feed already flushes it when the next stream cannot join) and accepts a 1-byte continuation stream.

@slint6614-dev

Copy link
Copy Markdown
Contributor

Checked on Linux: merged onto main dde82f2 (merges cleanly).

  • python3 -B tests/test_odrp_7a.py → OK
  • Negative control: with tools/odrp_7a.py reverted to main and the new test kept, 5 tests fail, so the test catches the bug.

Read the diff as well; it looks right to me.

@AsgerCode

Copy link
Copy Markdown

Tested 52808a5 on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass

What I ran:

  • python -I tests/test_odrp_7a.py: 18 tests, OK. tests/test_ped_catalogues.py (the other importer): 9 tests, OK.
  • Negative control (merge base's tools/odrp_7a.py): the 4 new cases fail, as the description says.
  • Each fix reverted alone: putting back the early _flush_pending() fails only the padding test; min_size = 64 fails only the two short-tail subtests; removing the _parse_psin_tail call in the LRSC branch fails only the 108-byte test. Each test covers its own fix.
  • Merge with current main (dde82f2, 256 commits ahead, none on odrp_7a): clean, both test files OK on the merged tree.
  • git diff --check and scripts/check_no_game_data.py: clean.
  • CLI on a synthetic RPF9 with a PSIN split 12 bytes before the end: exit 0, 1 record, complete: 1, psin_lrsc_joined: 1.

Edge cases, scan_rpf on hand-built RPF9 files (base = merge base's tool):

Input Base PR
standalone (496 B) split, tail 1 / 2 / 63 B at next_off incomplete, 1 stream, tail skipped complete, 2 streams, 496 B
same, tail 64 / 65 B complete, 2 streams same
PSIN (420 B) split, tail 1 / 12 / 21 / 63 B incomplete complete, 2 streams
PSIN tail 64 / 65 / 109 B complete same
24 or 63 B tail one 16-byte line after next_off incomplete same (not contiguous, still skipped)
empty zlib stream at next_off, then the 24 B tail incomplete same (0 B is under min_size 1)
invalid 78 9c ff ff in the padding before next_off incomplete (flushed) complete, 2 streams
valid 9-byte zlib stream (inflates to 1 B) in the padding incomplete complete, 2 streams
invalid header in the padding plus a 40 B tail (both fixes) incomplete complete
non-continuation LRSC prefix of 63 / 64 / 65 B no row / row / row same (64-byte cutoff unchanged)
107 / 108 / 109 B LRSC+CHKS stream lrsc_section incomplete, all three 107: lrsc_section; 108: psin_tail complete; 109 (extra byte at the end): lrsc_section

For the short tails, scan_dir on the same splits (carved .bin files plus index.json) gives the same joined rows as scan_rpf on the PR, which is the parity the description claims.

classify_blob checks: a 108 B tail with a bad LRSC payload, a CHKS that declares 21, or an LRSC that declares 89 all stay lrsc_section, incomplete. A bare 88 B section stays lrsc_section complete.

Docs: docs/restofworld.md (around line 293) says the tool joins contiguous 16-byte-aligned continuations and detects LRSC+CHKS tails. It does not mention the 64-byte limit, so it still reads correctly. Its table reports 0 incomplete records, so I expect no count change. I cannot re-run that table without game files.

Overlap: the other open odrp_7a PRs (#4021, #5157, #5891, #6127, #6395, #7470) each merge cleanly with this one. With #7470 merged in as well, tests/test_odrp_7a.py and tests/test_odrp_7a_parity.py both pass.

AI-assisted (Claude Code).

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.

4 participants