restofworld_index: an archive scan classifies a PSIN from its whole stream, not 256 bytes

scan_rpf passed classify only the first 256 inflated bytes, so a PSIN whose
section chain runs past them lost its tags and complete flag, while scan_dir
read the same resource whole. The PSIN stream is kept (already capped by
max_inflate) and classified like a carved file.
This commit is contained in:
quackottu
2026-11-22 12:08:47 +05:30
parent 48ad23f026
commit af55ea1b44
2 changed files with 15 additions and 2 deletions

View File

@ -247,6 +247,17 @@ class ArchiveTest(unittest.TestCase):
self.assertGreater(summary["readable_fraction"], 0.5)
self.assertEqual(summary["skipped_candidates"], 0)
def test_psin_longer_than_256_bytes_reads_the_whole_chain(self):
# Before: scan_rpf classified only the first 256 inflated bytes, so CHKS (at 0x140) was cut off.
data = (b"PSIN" + (16).to_bytes(4, "big") + struct.pack("<II", 22, 0)
+ b"LSCH" + (8 + 300).to_bytes(4, "big") + bytes(300) + b"CHKS" + (16).to_bytes(4, "big") + bytes(8))
rpf = os.path.join(self.root, "long_psin.rpf")
with open(rpf, "wb") as f:
f.write(b"9FPR" + struct.pack("<I", 16) + bytes(8) + zlib.compress(data) + bytes(64))
(row,), _ = restofworld_index.scan_rpf(rpf)
self.assertEqual((row["signature"], row["count"], row["detail"]),
("psin", 2, "tags=LSCH,CHKS;field8=22;complete=1"))
def test_scan_limit(self):
limit = self.offsets[2] - 0x100 - 1
rows, summary = restofworld_index.scan_rpf(self.rpf, limit=limit)

View File

@ -221,7 +221,7 @@ def scan_rpf(path, start=None, limit=None, max_inflate=MAX_INFLATE):
last = pos = s + blen
continue
d = zlib.decompressobj()
p, total, head = s, 0, b""
p, total, head, psin = s, 0, b"", bytearray()
too_big = False
try:
while not d.eof and p < end: # inside the --limit window, as in story_index (#712)
@ -239,6 +239,8 @@ def scan_rpf(path, start=None, limit=None, max_inflate=MAX_INFLATE):
break
if len(head) < 256:
head += chunk[:256 - len(head)]
if len(head) < 4 or head[:4] == b"PSIN": # classify walks the whole PSIN chain
psin += chunk
if not block:
break
if too_big:
@ -254,7 +256,7 @@ def scan_rpf(path, start=None, limit=None, max_inflate=MAX_INFLATE):
z, u = _gap(m[last:s])
zero += z
unread += u
row = classify(head, s, used)
row = classify(bytes(psin) if head[:4] == b"PSIN" else head, s, used)
row["size"] = total
rows.append(row)
last = pos = s + used