Skip to content

ptr_truncation_census: refuse one file for --json and --index-out (the index replaced the summary) - #5905

Merged
shayderrr merged 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/8-ptrcensus-same-out
Nov 23, 2026
Merged

shayderrr merged 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/8-ptrcensus-same-out

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

What changed and why

tools/ptr_truncation_census.py writes two reports: the summary to --json and the {number: {stage, user_sgpr_reads}} map to --index-out. Nothing checked that they are two different files, so

python -I tools/ptr_truncation_census.py <disasm> --json R.json --index-out R.json

wrote the summary to R.json, then wrote the index over it, and exited 0: the summary was silently lost. The new check refuses that pair before any listing is scanned, using tools/report_paths.same_report_path (the same helper the other --out guards use, so case spellings, hard links and case-folding volumes are one file too).

Test

python -I tests/test_ptr_truncation_census.py

Before the change (test present, tool unmodified):

......F...
FAIL: test_json_and_index_out_name_two_files
AssertionError: SystemExit not raised
Ran 10 tests in 0.051s
FAILED (failures=1)

After the change:

..........
Ran 10 tests in 0.064s
OK

By hand, with an empty folder so the guard is what stops the run:

rc 2
ptr_truncation_census.py: error: --json and --index-out name one file: ...\r.json; the second report would replace the first
wrote False

python -m compileall -q tools/ptr_truncation_census.py tests/test_ptr_truncation_census.py exits 0.

GPU: none needed.

Notes

  • Refused with ap.error (exit 2, message on stderr, nothing written), like the other tools' --out guards, rather than writing to a suffixed second name: the caller asked for two specific paths, and guessing a new one hides the mistake.
  • Only --json vs --index-out is checked; both may still name a file inside the scanned folder, because that folder is read-only for this tool.

AI-assisted.

The index was written after the summary with no check that the two paths are two files, so `--json R.json --index-out R.json` still exited 0 with the summary silently replaced by the index. tools/report_paths.same_report_path answers the one-file question (case, hard links and folding volumes), beside the other --out guards.
Runs the CLI with both outputs on one path: before the guard it wrote the index over the summary and returned 0, so the test failed with 'SystemExit not raised'; with it, exit 2 and the path stays absent.
@tahffo68hk-hash

Copy link
Copy Markdown
Contributor

Windows CPU check at d0ae9d836 combined with #5862 4653338bb: the merge is clean and all 10 pointer-census tests pass. I also checked the note about reports inside the scanned directory. A distinct disasm/report.json works and preserves the listing. Two output aliases still destroy an input:

  • Pass the scanned synthetic disasm/ps_table32.s as --json and a separate --index-out. The tool exits 0 and replaces the listing bytes with the summary.
  • Make an index.json hard link to that listing and use it for --index-out, with a separate summary path. The tool exits 0 and replaces the same listing through the hard link.

This is separate from the output/output collision covered here. A follow-up can check each output against discovered input paths with the same path helper and still allow a distinct report in the source folder. The listing came from the existing synthetic test helper. No GPU, AI-assisted.

在 Windows 上用 CPU 验证了 d0ae9d836 与 #5862 4653338bb 的组合。合并无冲突,10 项指针统计测试全部通过。我也验证了说明中关于扫描目录内报告的行为。独立的 disasm/report.json 可以正常写入,原清单保持完整。两种输出路径仍会破坏输入:

  • 把待扫描的合成 disasm/ps_table32.s 作为 --json,同时给 --index-out 指定另一条路径。工具以退出码 0 结束,并用汇总替换清单内容。
  • 将 index.json 硬链接到该清单,再用它作为 --index-out,同时给汇总指定另一条路径。工具以退出码 0 结束,并经硬链接覆盖同一个清单。

这与本 PR 处理的两个输出互相覆盖是独立问题。后续可以用同一个路径比较辅助函数检查每个输出和发现的输入路径,并继续允许把独立报告写入源目录。清单由现有合成测试辅助函数生成。未使用 GPU,AI 辅助。

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Reviewed correctness fix in PR #5905: ptr_truncation_census: refuse one file for --json and --index-out (the index replaced the summary).

Scope: tests/test_ptr_truncation_census.py, tools/ptr_truncation_census.py
Diff: +21 / -0 across 2 file(s).

The change stays inside the stated scope and the touched files line up with the description. No unrelated production paths are pulled in, and the stated behavior is directly exercised by the diff. I'm approving this one.

Reviewed by shayderrr via automated batch review.

@shayderrr

Copy link
Copy Markdown
Collaborator

Thanks @evilclanker9000 - I went through ptr_truncation_census: refuse one file for --json and --index-out (the index replaced t... and the diff around tests/test_ptr_truncation_census.py. The change is tight, the rationale matches the code, and there's nothing here that needs another pass from my side. Approved and squash-merging it into main now. Nice work.

@shayderrr
shayderrr merged commit eee10b8 into ItsNotRexed:main Nov 23, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants