From c0b1baa1d7009f5bc1c573403f1ca943f0e7a636 Mon Sep 17 00:00:00 2001 From: evilclanker9000 <45567075+evilclanker9000@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:54:59 +0100 Subject: [PATCH 1/2] restofworld_index: read a carve index.json saved with a UTF-8 BOM _carve_index opened index.json as strict UTF-8, so a BOM (PowerShell 5.1's Set-Content/Out-File default) made json.load raise, the except swallowed it as {}, and the inflated length on disk was reported as the stored size. --- tools/restofworld_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/restofworld_index.py b/tools/restofworld_index.py index e0ca109ef9..761dbcc773 100644 --- a/tools/restofworld_index.py +++ b/tools/restofworld_index.py @@ -372,7 +372,7 @@ def scan_rpf(path, start=None, limit=None, max_inflate=MAX_INFLATE): def _carve_index(path): """rpf9_carve.py's index.json in `path`: ({file name: stored bytes}, summary), or ({}, {}) without one.""" try: - with open(os.path.join(path, "index.json"), encoding="utf-8") as f: + with open(os.path.join(path, "index.json"), encoding="utf-8-sig") as f: index = json.load(f) stored = {f"{int(e['off']):012x}.bin": int(e["stored"]) for e in index.get("files", [])} summary = index.get("summary", {}) From 714f5824c938917bff00cbd6e6c71bc7335d9b67 Mon Sep 17 00:00:00 2001 From: evilclanker9000 <45567075+evilclanker9000@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:55:07 +0100 Subject: [PATCH 2/2] test_restofworld_index: a BOM'd carve index still supplies the stored sizes Without the utf-8-sig read the folder mode reports 1000 (the inflated length on disk) instead of the 300 stored bytes the index names. --- tests/test_restofworld_index.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/test_restofworld_index.py b/tests/test_restofworld_index.py index 7978a2cc5d..07a55792f1 100644 --- a/tests/test_restofworld_index.py +++ b/tests/test_restofworld_index.py @@ -504,14 +504,14 @@ class FolderModeStoredBytesTest(unittest.TestCase): """A carve folder's stored (compressed) sizes and span come from rpf9_carve.py's index.json, as in archive mode; without an index the length on disk is all there is.""" - def make(self, tmp, with_index): + def make(self, tmp, with_index, encoding="utf-8"): data = b"raw bytes " * 100 # 1,000 inflated bytes with open(os.path.join(tmp, "000000001000.bin"), "wb") as f: f.write(data) if with_index: index = {"summary": {"span": 2000, "zero_padding": 500, "unread_bytes": 1200}, "files": [{"off": 0x1000, "stored": 300, "size": 1000}]} - with open(os.path.join(tmp, "index.json"), "w", encoding="utf-8") as f: + with open(os.path.join(tmp, "index.json"), "w", encoding=encoding) as f: json.dump(index, f) def test_index_json_supplies_stored_bytes_and_span(self): @@ -522,6 +522,16 @@ def test_index_json_supplies_stored_bytes_and_span(self): self.assertEqual((summary["compressed_bytes"], summary["inflated_bytes"]), (300, 1000)) self.assertAlmostEqual(summary["readable_fraction"], 300 / 2000, places=4) + def test_index_json_saved_with_a_bom_supplies_stored_bytes(self): + """A carve index.json saved with a UTF-8 BOM (PowerShell 5.1's default) still supplies the stored sizes. + Read as plain UTF-8, json.load failed, _carve_index returned {}, and the inflated length on disk was + reported as the stored size.""" + with tempfile.TemporaryDirectory() as tmp: + self.make(tmp, with_index=True, encoding="utf-8-sig") + rows, summary = restofworld_index.scan_dir(tmp) + self.assertEqual(rows[0]["stored"], 300) + self.assertEqual(summary["compressed_bytes"], 300) + def test_without_an_index_the_length_on_disk_is_used(self): with tempfile.TemporaryDirectory() as tmp: self.make(tmp, with_index=False)