Skip to content

image_fuzz: reject a --work that is a file before the fuzz starts - #4087

Closed
tupacfan04 wants to merge 2 commits into
ItsNotRexed:mainfrom
tupacfan04:fix/image-fuzz-work-folder
Closed

tupacfan04 wants to merge 2 commits into
ItsNotRexed:mainfrom
tupacfan04:fix/image-fuzz-work-folder

Conversation

@tupacfan04

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new BUILD item (claim).

What and why

tools/image_fuzz.py --work <a file> reached os.makedirs(work, exist_ok=True) after make_cases() had built every case, and died with a raw FileExistsError traceback. The same happened for a --work under a regular file.

Tested

  • tests/test_image_fuzz.py: 63 passed, including two new cases (--work is a file; --work under a file), each asserting exit 2, the message, no traceback, and that the existing file's contents are unchanged.
  • Negative control: the same test file on origin/main (aa2988cc) fails exactly those two, 61 passed.
  • python -m compileall -q tools/image_fuzz.py tests/test_image_fuzz.py.
  • Windows 11 (build 26300), Python 3.13.0. No game files, no GPU.

AI-assisted: written by an AI coding agent (OpenCode) and checked by the commands above.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not a translator change.)

Depends on: #3770 (same --work lines; whichever lands second needs a trivial rebase).

A --work pointing at a file (or under one) reached os.makedirs after the cases were built and died with a raw FileExistsError traceback. Validate the destination (or its nearest existing parent) right after the argument checks, so it is one ERROR line and exit 2 before any work.
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Second check on Windows at 4d3280e. With case generation and translation mocked, the base reached case generation and then raised a filesystem exception for both a regular file and a nested path beneath it. This head returned 2 with one --work diagnostic, before either mock was called, and preserved the file bytes. A new directory below an existing directory and the default scratch directory each reached the stub driver once and returned 0 on both revisions. No fuzz or native tool was launched.

AI-assisted.

@TG0000

TG0000 commented Nov 23, 2026

Copy link
Copy Markdown

Tested 4d3280e9 on macOS arm64, Python 3.14.9. A regular file and a child path under a regular file both return 2 before make_cases, as intended. A dangling directory symlink passed as --work still raises FileExistsError after case generation. Passing a child under that link raises FileNotFoundError at the same point.

exists() ignores the broken link, so the preflight walks past it. Changing both os.path.exists(probe) checks to os.path.lexists(probe) catches that existing directory entry while allowing valid directory symlinks through isdir(). I checked the two broken-link cases, the two regular-file cases, a valid directory link and its child, and a new nested directory. All seven behaved as expected after the change, with the original file and symlink preserved.

AI-assisted. The Vulkan backend was stubbed. No GPU or game files were used.

@TG0000 TG0000 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested 4d3280e9 on Windows 11 build 26300 with CPython 3.12.10. The 63 tests in tests/test_image_fuzz.py pass with pytest 9.2.0.

A dangling NTFS directory junction supplied as --work still reaches make_cases and then raises FileExistsError. A child path under the junction raises FileNotFoundError after case generation. exists() skips the dangling junction during preflight. Changing both os.path.exists(probe) checks to os.path.lexists(probe) returned 2 with a single --work diagnostic before make_cases in both cases. Retested all seven paths: regular file, its child, dangling junction, its child, live junction, its child, and a new nested directory. The original file and junction stayed intact, and valid directories were accepted.

AI-assisted (OpenAI Codex). Case generation and the Vulkan runner were mocked. Synthetic paths only.

@memorypressure

Copy link
Copy Markdown

Verified on Linux: merges cleanly into main (aa2988c), compileall clean, and tests/test_image_fuzz.py passes 63/63 under pytest (61/61 on plain main, so the delta is exactly your two new tests); under python -I it fails loudly on import pytest rather than silently running nothing. The check runs before cases are built and before any work dir is created, and both the direct --work <file> and --work <file>/sub paths exit 2 with no traceback, leaving the file untouched. Two nits: the diff adds a UTF-8 BOM at the top of tests/test_image_fuzz.py (main has none — please drop it) and a trailing blank line at EOF; and #4152 also touches tools/image_fuzz.py, so expect an interaction there. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

Use lexists for the destination probe, so a dangling symlink or junction is
reported as "not a folder" instead of being treated as missing and failing in
makedirs. Strip the BOM and trailing blank line from the new test file, and add
a symlink case that skips where symlinks cannot be created.
@tupacfan04

Copy link
Copy Markdown
Contributor Author

Addressed the two post-review points in 3dc08ade:

  • The destination probe now uses os.path.lexists, so a dangling symlink or junction is reported as ERROR: --work is not a folder instead of being treated as missing and failing later in makedirs.
  • The test file had a UTF-8 BOM and a trailing blank line (from my editor); both are gone, and it is LF-only now.
  • Added test_work_that_is_a_dangling_symlink_is_a_usage_error, which skips where symlinks cannot be created (it skips on this unprivileged Windows account).

Re-checked: tests/test_image_fuzz.py is 63 passed, 1 skipped. The two non-symlink cases still fail on main's tool as before. #4152 also touches image_fuzz.py but does not conflict at the moment.

AI-assisted, no game files, no GPU.

@tupacfan04

Copy link
Copy Markdown
Contributor Author

Closing as superseded.

main now treats --work as the parent for a per-run temp directory and catches OSError around os.makedirs(parent, exist_ok=True) + mkdtemp, printing one ERROR: cannot create work directory: ... line and returning 2 (the merged content of #3770, whose PR is still open). That covers the --work-is-a-file case this PR was about, with a one-line error instead of a traceback.

Because --work is no longer the work directory itself, the lexists probe added here no longer matches the contract, so there is nothing to salvage. The two symlink/file cases and the BOM cleanup were checked at the time (3dc08ade), but they are moot under the new semantics.

Thanks to the auditors for spotting the overlap before it wasted a rebase.

AI-assisted, no game files.

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.

4 participants