`--out` is written by PIL with no checks: pointing it at the blob being probed
opened the sample for the read and then saved the preview over it, truncating
the very bytes the probe had just read (`tile_probe shot.bin --out shot.bin`
leaves shot.bin as a PNG). A folder that did not exist was a PIL traceback
after the whole probe had already run, and a Pillow install in the --user
site is invisible to the documented `python -I` invocation, which was a
ModuleNotFoundError from inside render() at the same late point.
The path checks now run before the read: refuse a directory, refuse the input
(realpath plus samefile, so a different spelling of the same file is caught),
create the preview's folder, and give Pillow's absence one line at render
time. amd_swizzle imports the same helper for its own preview.
When every candidate was rejected (a sample shorter than 16 rows of blocks at
any of the widths) main() printed nothing, wrote no preview and returned 0, so
a script saw a successful run with no result. The empty-file and bad-offset
paths already exit 1, and tools/swizzle_search.py treats the same outcome as
one ERROR line, so match it: name the input and offset, exit 1.
Tests: an 8-byte and a 4 KiB blob, with and without --out, must exit 1, print
one line naming the file, and leave no preview; the 16 KiB case still probes
and exits 0.
Negative control on main: both new subtests fail (exit 0, no message). With
the change: 5/5. No game data.
🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
A missing file stopped with a traceback. A negative --offset silently probed the last bytes of the file
(Python slicing from the end), and an offset at or past the end printed nothing and exited 0, which looks like
"no layout found". Both now exit 1 with the offset and the file size; an empty file reports 0 bytes.
Tests: tests/test_tile_probe.py (new; skips without numpy, which the tool needs).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>