One function

safe_write_bytes in guillaumemeyer/watermarks-remover

The author described this change as fix: guard os.fchmod for non-POSIX platforms (#15). It counts as a record because the check below fails on the code as it stood at f10efaa7e and passes on 6e5f9ce84, with nothing else changed between the two runs.

Fix saved2026-08-13
Sharing licenceMIT · LICENSE
Change size+4 2

What the code was meant to do, written into the code itself as a docstring

Atomically write bytes to *path* without following symlinks. Writes to a temp file in the destination directory and `os.replace`s it into place. `os.replace` replaces a symlink rather than following it, and the explicit symlink check gives a clear error instead of surprising behavior. This defeats pre-placed symlinks (e.g. in /tmp or download dirs) redirecting a clean write onto an arbitrary victim file.

The change

1515 fd, tmp_name = tempfile.mkstemp(prefix=f".{dest.name}.", suffix=".tmp", dir=str(parent))
1616 try:
1717 # mkstemp creates 0600; restore the umask-default mode so outputs
18- # keep normal permissions.
19- os.fchmod(fd, _default_file_mode())
18+ # keep normal permissions. Windows has no fchmod and no POSIX mode
19+ # bits to restore, so the call is skipped there.
20+ if hasattr(os, "fchmod"):
21+ os.fchmod(fd, _default_file_mode())
2022 with os.fdopen(fd, "wb") as f:
2123 f.write(data)
2224 f.flush()

The check that tells the two apart

failpass·tests/test_security_hardening.py::test_safe_write_bytes_without_fchmod

Check file tests/test_security_hardening.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itf10efaa7efc75591b4744cc1d885874a79f5f7ee
Broken version dated2026-08-13
Moduleskills.remove-ai-marks.scripts.common
Units changedsafe_write_bytes
Fingerprintfdda8f4fe3d66d38
Checked2026-08-17 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in guillaumemeyer/watermarks-remover