Skip to content

Compress long log names that gzip accepts - #79

Merged
HaoZeke merged 1 commit into
developfrom
fix/gzip-long-name-overflow-241120
Nov 21, 2026
Merged

HaoZeke merged 1 commit into
developfrom
fix/gzip-long-name-overflow-241120

Conversation

@HaoZeke

@HaoZeke HaoZeke commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

gzipInPlace compresses through a temporary file named .<name>.<pid>.<hex>.tmp, so a log name well inside what gzip -9 accepts can push that one path component past the filesystem's 255-byte limit. A 232-byte name can already overflow it, depending on the pid; gzip -9 takes names up to 252 bytes.

The pid and the random suffix already keep two temporary files apart, so the original name is left out of the temporary name when including it would overflow a component.

The new test uses a 240-byte name. Without this commit it fails with the real NameTooLong from the kernel's ENAMETOOLONG on openat, with 201 of 202 tests passing. With this commit zig build test passes 202 of 202 with no skips, on Zig 0.17.1 and Python 3.14.10.

The fix is independent of the sys.Ops fault-injection work. The same .{name}.{pid}.{hex}.tmp pattern also appears in src/atomic.zig and src/fsx.zig tmpName, which this change leaves alone.

A run directory's log can carry a name close to a filesystem's own
255-byte limit on one path component. It can still sit well inside
what the reference compressor at its highest setting allows. Its own
overhead is just the three bytes of the `.gz` suffix it adds.
`gzipInPlace` writes its compressed bytes to a temporary name first.
That way a crash or a short write cannot leave a partial archive under
the final name a later run would skip. The temporary name carried the
original name in full, plus a pid and a random suffix guarding it from
a concurrent or a retried run. Nothing checked whether the result
still fit in one path component once that suffix was added on. A name
as short as 232 bytes, well under the reference tool's own limit,
could report NameTooLong.

The pid and the random suffix alone are already enough to keep two
temporary files from colliding in the same directory. The original
name is left out of the temporary one when adding it on would overflow
a path component. That way a compression the final name alone would
have gone on to complete does not fail. A name under the reference
compressor's own 252-byte limit compresses here too, regardless of the
temporary name's own overhead. One past even that limit still reports
NameTooLong, exactly as the reference tool itself would refuse it.

A 240-byte name is picked so the prior temporary name overflows
whatever the running process's own pid happens to be. It reports
NameTooLong on the parent commit, and compresses here. A full
`zig build test` run reports every other case still passing.
@HaoZeke
HaoZeke changed the base branch from main to develop November 21, 2026 05:32
@HaoZeke
HaoZeke merged commit 02ccd57 into develop Nov 21, 2026
8 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.

1 participant