From 76b5d1935429a2abe6fb14162cde1364a4a964c2 Mon Sep 17 00:00:00 2001 From: Anonymous78e <123822114+Anonymous78e@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:13:41 +0100 Subject: [PATCH] pe_inspect: ask report_paths for the report-path guard (PE-INSPECT-SHARED-REPORT-PATH) tools/pe_inspect.py carried a private same_output_path (realpath + normcase + samefile). CONTRIBUTING asks report writers to use tools/report_paths.same_report_path, which also folds case on a case-insensitive macOS volume where normcase does not, and samefile cannot see a report that is not written yet. same_output_path stays as its alias. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014sDZDAAcsauTL6d8ie67Qo --- tests/test_pe_inspect.py | 16 ++++++++++++++++ tools/pe_inspect.py | 15 +++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/test_pe_inspect.py b/tests/test_pe_inspect.py index 1d47c0575..4c0cb1228 100644 --- a/tests/test_pe_inspect.py +++ b/tests/test_pe_inspect.py @@ -382,6 +382,22 @@ class PeInspectTest(unittest.TestCase): self.assertEqual(r["pdata_functions"], 0) self.assertFalse(r["has_relocs"]) + def test_case_only_spelling_of_a_missing_report_is_one_path(self): + # normcase keeps case on macOS, and samefile cannot see a report that has not been written yet. + with tempfile.TemporaryDirectory() as tmp: + folder = os.path.join(tmp, "Reports") + os.mkdir(folder) + probe = os.path.join(folder, "Probe.tmp") + with open(probe, "wb"): + pass + insensitive = os.path.exists(os.path.join(folder, "probe.tmp")) + os.remove(probe) + if not insensitive: + self.skipTest("volume keeps case") + first = os.path.join(tmp, "Reports", "game.exe.json") + second = os.path.join(tmp, "reports", "game.exe.json") + self.assertTrue(pe_inspect.same_output_path(first, second)) + def test_cli_reports_an_unusable_output_directory(self): out = os.path.join(self.dir, "report-file") with open(out, "w", encoding="utf-8") as f: diff --git a/tools/pe_inspect.py b/tools/pe_inspect.py index 42de08ce4..da5aeeace 100644 --- a/tools/pe_inspect.py +++ b/tools/pe_inspect.py @@ -32,6 +32,11 @@ import sys from collections import Counter from collections.abc import Iterator +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from report_paths import same_report_path # noqa: E402 + +same_output_path = same_report_path # True when writing the second would truncate the first + SYSTEM32 = os.path.join(os.environ.get("SystemRoot", r"C:\Windows"), "System32") # Whether this host is Windows: there SYSTEM32 and the OS API-set schema answer `system`; elsewhere a Wine prefix's # system32 does (classify_dll). A module flag so that a test can stand in for either host. @@ -978,16 +983,6 @@ def version_summary(r: dict) -> str | None: + (f", problems: {len(res['problems'])}" if res["problems"] else "")) -def same_output_path(first: str, second: str) -> bool: - """True when writing ``second`` would truncate ``first`` (same file, path or hard link).""" - 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 main(argv: list[str] | None = None) -> int: ap = argparse.ArgumentParser() ap.add_argument("image", nargs="+")