diff options
| author | evilclanker9000 <45567075+evilclanker9000@users.noreply.github.com> | 2026-11-23 16:42:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-23 09:42:37 -0600 |
| commit | 167feec51250db18a59155c1d20e02dc43ec01ac (patch) | |
| tree | b1122fe11785389ff7927edda6389869902bcd0a | |
| parent | 5278085d06d737c0dee98872809f0d3362e6cf6e (diff) | |
mission_tables: refuse a single named file that is not a PSIN container (#6926)
Squash-merged after diff review of PR #6926 - mission_tables: refuse a single named file that is not a PSIN container
| -rw-r--r-- | docs/mission_logic.md | 4 | ||||
| -rw-r--r-- | tests/test_mission_tables.py | 22 | ||||
| -rw-r--r-- | tools/mission_tables.py | 11 |
3 files changed, 37 insertions, 0 deletions
diff --git a/docs/mission_logic.md b/docs/mission_logic.md index 67a15ebf1..d1ee15e51 100644 --- a/docs/mission_logic.md +++ b/docs/mission_logic.md | |||
| @@ -166,6 +166,10 @@ at, from inflated PSIN streams or a directory of carved `.bin` streams: | |||
| 166 | python -I tools/mission_tables.py <file-or-dir> [--json] [--limit N] | 166 | python -I tools/mission_tables.py <file-or-dir> [--json] [--limit N] |
| 167 | ``` | 167 | ``` |
| 168 | 168 | ||
| 169 | A lone path is the PSIN file: a file without the `PSIN` magic is one `ERROR: <path>: not a PSIN container` | ||
| 170 | line and exit 2, while a folder is the place for the bare carved streams and is scanned as before. A PSIN | ||
| 171 | file that holds no records is still a clean run. | ||
| 172 | |||
| 169 | It prints per-file record, chunk, state and entity counts, plus each resolved entity's archetype | 173 | It prints per-file record, chunk, state and entity counts, plus each resolved entity's archetype |
| 170 | hash, link hash, position and rotation. Pointers are scored in three encodings: **file-absolute**, | 174 | hash, link hash, position and rotation. Pointers are scored in three encodings: **file-absolute**, |
| 171 | **linked pool** (`pool_block_base + (offset >> 4)`), and **block-indexed** (`kind` is a 1-based | 175 | **linked pool** (`pool_block_base + (offset >> 4)`), and **block-indexed** (`kind` is a 1-based |
diff --git a/tests/test_mission_tables.py b/tests/test_mission_tables.py index 43879eff1..5cdad139d 100644 --- a/tests/test_mission_tables.py +++ b/tests/test_mission_tables.py | |||
| @@ -413,6 +413,28 @@ class TestCli(unittest.TestCase): | |||
| 413 | self.assertEqual(completed.stdout.count(" records="), 2) | 413 | self.assertEqual(completed.stdout.count(" records="), 2) |
| 414 | self.assertIn("2 files,", completed.stdout) | 414 | self.assertIn("2 files,", completed.stdout) |
| 415 | 415 | ||
| 416 | def test_a_single_file_without_the_magic_is_refused(self): | ||
| 417 | # A lone argument is a PSIN file; a folder is where the bare carved .bin streams live. Naming a file | ||
| 418 | # that is neither used to end in "1 files, 0 records" and exit 0, so a wrong path looked like a run. | ||
| 419 | with tempfile.TemporaryDirectory() as folder: | ||
| 420 | path = os.path.join(folder, "not-a-container.bin") | ||
| 421 | with open(path, "wb") as handle: | ||
| 422 | handle.write(b"\x01" * 64) | ||
| 423 | completed = subprocess.run([sys.executable, "-I", TOOL, path], capture_output=True, text=True) | ||
| 424 | self.assertEqual(completed.returncode, 2) | ||
| 425 | self.assertIn("not a PSIN container", completed.stderr) | ||
| 426 | self.assertEqual(completed.stdout, "") | ||
| 427 | |||
| 428 | def test_a_folder_still_scans_a_stream_without_the_magic(self): | ||
| 429 | # Negative control: the same bytes in a folder are a carved stream and are still counted. | ||
| 430 | with tempfile.TemporaryDirectory() as folder: | ||
| 431 | with open(os.path.join(folder, "bare.bin"), "wb") as handle: | ||
| 432 | handle.write(b"\x01" * 64) | ||
| 433 | completed = subprocess.run([sys.executable, "-I", TOOL, folder], capture_output=True, text=True) | ||
| 434 | self.assertEqual(completed.returncode, 0, completed.stderr) | ||
| 435 | self.assertIn("1 files, 0 records", completed.stdout) | ||
| 436 | self.assertIn("skipped bytes 64", completed.stdout) | ||
| 437 | |||
| 416 | 438 | ||
| 417 | if __name__ == "__main__": | 439 | if __name__ == "__main__": |
| 418 | unittest.main() | 440 | unittest.main() |
diff --git a/tools/mission_tables.py b/tools/mission_tables.py index f093048a6..f8299a900 100644 --- a/tools/mission_tables.py +++ b/tools/mission_tables.py | |||
| @@ -552,6 +552,17 @@ def main(argv=None): | |||
| 552 | if not os.path.exists(args.src): | 552 | if not os.path.exists(args.src): |
| 553 | print(f"ERROR: {args.src}: no such file or folder", file=sys.stderr) | 553 | print(f"ERROR: {args.src}: no such file or folder", file=sys.stderr) |
| 554 | return 2 | 554 | return 2 |
| 555 | if os.path.isfile(args.src): | ||
| 556 | # A lone argument is the inflated PSIN file; the bare carved streams are what a folder holds. | ||
| 557 | try: | ||
| 558 | with open(args.src, "rb") as handle: | ||
| 559 | magic = handle.read(4) | ||
| 560 | except OSError as error: | ||
| 561 | print(f"ERROR: {args.src}: {error}", file=sys.stderr) | ||
| 562 | return 2 | ||
| 563 | if magic != b"PSIN": | ||
| 564 | print(f"ERROR: {args.src}: not a PSIN container", file=sys.stderr) | ||
| 565 | return 2 | ||
| 555 | try: | 566 | try: |
| 556 | files = collect(args.src, args.limit) | 567 | files = collect(args.src, args.limit) |
| 557 | except OSError as error: | 568 | except OSError as error: |