From 9cc9fded79805ea7aad6443136e266692709e231 Mon Sep 17 00:00:00 2001 From: dash Date: Tue, 24 Nov 2026 19:06:53 -0500 Subject: [PATCH 1/2] meshlet_page: treat case-only report paths as one file. On a case-insensitive volume, normcase left carve/index.json and CARVE/index.json as two paths, so --json could write the carve manifest. The shared report-path check refuses that spelling. Co-authored-by: Cursor --- tests/test_meshlet_page.py | 20 ++++++++++++++++++++ tools/meshlet_page.py | 12 +++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/test_meshlet_page.py b/tests/test_meshlet_page.py index abf82d05de..9f6740796c 100644 --- a/tests/test_meshlet_page.py +++ b/tests/test_meshlet_page.py @@ -1038,6 +1038,26 @@ def test_json_cannot_create_a_report_in_place_of_the_carve_manifest(self): self.assertNotIn("Traceback", r.stderr) self.assertFalse(os.path.exists(manifest)) + def test_json_cannot_create_the_manifest_under_another_case(self): + # normcase keeps case on macOS, so carve/index.json and CARVE/index.json used to pass as two paths. + with tempfile.TemporaryDirectory() as tmp: + carve = os.path.join(tmp, "carve") + os.mkdir(carve) + with open(os.path.join(carve, "0000.bin"), "wb") as fh: + fh.write(page(block(4))) + probe = os.path.join(carve, "Probe.tmp") + with open(probe, "wb"): + pass + insensitive = os.path.exists(os.path.join(carve, "probe.tmp")) + os.remove(probe) + if not insensitive: + self.skipTest("volume keeps case") + other = os.path.join(tmp, "CARVE", "index.json") + r = self.run_tool(carve, "--json", other, "--quiet") + self.assertEqual(r.returncode, 2, r.stderr) + self.assertIn("would overwrite the input", r.stderr) + self.assertFalse(os.path.exists(os.path.join(carve, "index.json"))) + def test_json_over_carve_dir_manifest_or_payload_is_refused(self): with tempfile.TemporaryDirectory() as tmp: carve = os.path.join(tmp, "carve") diff --git a/tools/meshlet_page.py b/tools/meshlet_page.py index 71460068ea..ab0c15c183 100644 --- a/tools/meshlet_page.py +++ b/tools/meshlet_page.py @@ -76,6 +76,9 @@ import sys import zlib +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) # -I keeps the script directory off sys.path +from report_paths import same_report_path as same_output_path # noqa: E402 + BLOCK_MAGIC = 0x3063 OTHER_BLOCK_MAGIC = 0x4042 HEADER_SIZE = 0x60 @@ -915,15 +918,6 @@ def buffer(at): return {"vertex_block": vertex, "meshlet_group": index, "vertices": count} -def same_output_path(first, second): - if os.path.normcase(os.path.realpath(first)) == os.path.normcase(os.path.realpath(second)): - return True - try: - return os.path.samefile(first, second) - except OSError: - return False - - def is_scanned_input(path, input_path): """True when a report path is one of the files the scan reads: writing it would destroy the input.""" if same_output_path(path, input_path): From ba4e7ef6572527ff08dfd9a03fc9724279f25fa2 Mon Sep 17 00:00:00 2001 From: dash Date: Tue, 24 Nov 2026 19:30:45 -0500 Subject: [PATCH 2/2] meshlet_page: refuse a page report under another case of the carve folder. The manifest check folded case, but a page.bin inside the folder was still compared with normcase(abspath()), which keeps the typed case on macOS. CARVE/0000.bin could replace carve/0000.bin. Co-authored-by: Cursor --- tests/test_meshlet_page.py | 23 +++++++++++++++++++++++ tools/meshlet_page.py | 11 +++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/test_meshlet_page.py b/tests/test_meshlet_page.py index 9f6740796c..763200e926 100644 --- a/tests/test_meshlet_page.py +++ b/tests/test_meshlet_page.py @@ -1058,6 +1058,29 @@ def test_json_cannot_create_the_manifest_under_another_case(self): self.assertIn("would overwrite the input", r.stderr) self.assertFalse(os.path.exists(os.path.join(carve, "index.json"))) + def test_json_cannot_replace_a_page_under_another_case_of_the_folder(self): + # normcase(abspath()) keeps case on macOS, so CARVE/0000.bin was not inside carve. + with tempfile.TemporaryDirectory() as tmp: + carve = os.path.join(tmp, "carve") + os.mkdir(carve) + bin_path = os.path.join(carve, "0000.bin") + data = page(block(4)) + with open(bin_path, "wb") as fh: + fh.write(data) + probe = os.path.join(carve, "Probe.tmp") + with open(probe, "wb"): + pass + insensitive = os.path.exists(os.path.join(carve, "probe.tmp")) + os.remove(probe) + if not insensitive: + self.skipTest("volume keeps case") + other = os.path.join(tmp, "CARVE", "0000.bin") + r = self.run_tool(carve, "--json", other, "--quiet") + self.assertEqual(r.returncode, 2, r.stderr) + self.assertIn("would overwrite the input", r.stderr) + with open(bin_path, "rb") as fh: + self.assertEqual(fh.read(), data) + def test_json_over_carve_dir_manifest_or_payload_is_refused(self): with tempfile.TemporaryDirectory() as tmp: carve = os.path.join(tmp, "carve") diff --git a/tools/meshlet_page.py b/tools/meshlet_page.py index ab0c15c183..4c8e17248e 100644 --- a/tools/meshlet_page.py +++ b/tools/meshlet_page.py @@ -77,7 +77,7 @@ import zlib sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) # -I keeps the script directory off sys.path -from report_paths import same_report_path as same_output_path # noqa: E402 +from report_paths import path_key, same_report_path as same_output_path # noqa: E402 BLOCK_MAGIC = 0x3063 OTHER_BLOCK_MAGIC = 0x4042 @@ -929,9 +929,12 @@ def is_scanned_input(path, input_path): return True if not os.path.isfile(path): return False - root = os.path.normcase(os.path.abspath(input_path)) - target = os.path.normcase(os.path.abspath(path)) - if os.path.dirname(target) != root and not target.startswith(root + os.sep): + # path_key folds case on a volume that ignores it. normcase(abspath()) keeps the typed case on macOS, so a + # page.bin inside CARVE was not seen as inside carve. + root = path_key(input_path) + target = path_key(path) + prefix = root if root.endswith(os.sep) else root + os.sep + if target != root and not target.startswith(prefix): return False base = os.path.basename(target) return base.endswith(".bin") or base.endswith(".rpf")