[PR #2388] restofworld_index: judge text on the same 512 bytes in an archive (RESTOFWORLD-INDEX-TEXT-SAMPLE) #2389

Open
opened 2026-11-26 21:21:04 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2388
Author: @syfyra
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/restofworld-index-text-sample


📝 Commits (1)

  • 16dde22 restofworld_index: judge text on the same 512 bytes in an archive (RESTOFWORLD-INDEX-TEXT-SAMPLE)

📊 Changes

2 files changed (+13 additions, -2 deletions)

View changed files

📝 tests/test_restofworld_index.py (+11 -0)
📝 tools/restofworld_index.py (+2 -2)

📄 Description

Claimed in the coordination issue as: RESTOFWORLD-INDEX-TEXT-SAMPLE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7198290287)

What and why

tools/restofworld_index.py classifies each zlib stream of an RPF9 archive, or each carved file of a folder, by its first bytes. Its text class comes from _printable, which samples the first 512 bytes: text when the sample is at least 64 bytes and more than 90% printable.

A carved file is classified from its whole data. scan_rpf keeps a stream whole only when it may be a PSIN or a CPU resource (texture scan). For every other stream it passed classify a 256-byte head, so _printable saw at most 256 bytes there. One stream could therefore get two signatures. A stream whose first 306 bytes are printable, followed by binary data, read as text from the archive and as raw:6e616d65 from its carved file. af55ea1b4 removed the same archive-versus-folder split for PSIN streams.

The archive scan now keeps a 512-byte head, the sample _printable takes. The other head checks (PSIN, CPU-resource prefix) read at most 16 bytes, so nothing else changes. A stream that was text under the 256-byte sample is still text unless bytes 256-511 bring it under 90% printable, which is what a carved-file scan already says.

Different topic from #1535 (validation and I/O, same files); the two merge cleanly.

Tested

Windows 11, Python 3.14.7, synthetic streams only:

  • python -I tests/test_restofworld_index.py: 35 tests OK. New test_text_is_judged_on_the_same_512_bytes_as_a_carved_file puts the stream above into an archive and expects the signature classify gives for its whole data, which is not text. On main it gets 'text' != 'raw:6e616d65'. The existing signature, PSIN-chain and scan tests are unchanged.
  • python -m compileall; scripts/check_no_game_data.py on both files.

Not measured: how many streams of a real archive change class (no game files here).

GPUs tested: n/a (CPU-only tool)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code


🔄 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/2388 **Author:** [@syfyra](https://github.com/syfyra) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/restofworld-index-text-sample` --- ### 📝 Commits (1) - [`16dde22`](https://github.com/ubiquitarianism/leonida/commit/16dde22775fbf74dc3a99d28d2dd9f0c03d352df) restofworld_index: judge text on the same 512 bytes in an archive (RESTOFWORLD-INDEX-TEXT-SAMPLE) ### 📊 Changes **2 files changed** (+13 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_restofworld_index.py` (+11 -0) 📝 `tools/restofworld_index.py` (+2 -2) </details> ### 📄 Description Claimed in the coordination issue as: RESTOFWORLD-INDEX-TEXT-SAMPLE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7198290287) ### What and why `tools/restofworld_index.py` classifies each zlib stream of an RPF9 archive, or each carved file of a folder, by its first bytes. Its `text` class comes from `_printable`, which samples the **first 512 bytes**: text when the sample is at least 64 bytes and more than 90% printable. A carved file is classified from its whole data. `scan_rpf` keeps a stream whole only when it may be a PSIN or a CPU resource (texture scan). For every other stream it passed `classify` a **256-byte** head, so `_printable` saw at most 256 bytes there. One stream could therefore get two signatures. A stream whose first 306 bytes are printable, followed by binary data, read as `text` from the archive and as `raw:6e616d65` from its carved file. af55ea1b4 removed the same archive-versus-folder split for PSIN streams. The archive scan now keeps a 512-byte head, the sample `_printable` takes. The other head checks (PSIN, CPU-resource prefix) read at most 16 bytes, so nothing else changes. A stream that was text under the 256-byte sample is still text unless bytes 256-511 bring it under 90% printable, which is what a carved-file scan already says. Different topic from #1535 (validation and I/O, same files); the two merge cleanly. ### Tested Windows 11, Python 3.14.7, synthetic streams only: - `python -I tests/test_restofworld_index.py`: 35 tests OK. New `test_text_is_judged_on_the_same_512_bytes_as_a_carved_file` puts the stream above into an archive and expects the signature `classify` gives for its whole data, which is not `text`. On `main` it gets `'text' != 'raw:6e616d65'`. The existing signature, PSIN-chain and scan tests are unchanged. - `python -m compileall`; `scripts/check_no_game_data.py` on both files. Not measured: how many streams of a real archive change class (no game files here). GPUs tested: n/a (CPU-only tool) AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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#2389
No description provided.