Skip to content

fmt: format readable files when metadata lookup fails - #17053

Open
limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fmt-read-without-metadata
Open

limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fmt-read-without-metadata

Conversation

@limadog9

@limadog9 limadog9 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

fmt could open a readable file and discard its contents when a metadata lookup failed. Read the file and report errors from the read itself. Preserve directory diagnostics on affected BSD and WASI targets.

Addresses the fmt case in #10890 and compatibility tracker #14705.

With an injected metadata overflow, upstream main exited 1 with empty output. The fix formats the file and exits 0. The fmt case in GNU 9.12 misc/read-errors.sh now passes; other utilities still fail. All five GNU fmt tests pass. Linux integration tests went from 53 passed and 1 failed to 54 passed, with 2 ignored in both runs.

Comment thread src/uu/fmt/src/fmt.rs
return Ok(());
}
// Some BSD filesystems allow directory reads. WASI Preview 1 reports EBADF.
#[cfg(any(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how was this list picked? was it checked on the freebsd CI job?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, the FreeBSD Tests job passed on 6c81de6: https://github.com/uutils/coreutils/actions/runs/46557164454/job/142335034390

DragonFlyBSD and NetBSD are on the list because their UFS implementations can allow directory reads. FreeBSD also allows them on supported filesystems when running as root with security.bsd.allow_read_dir enabled. The CI job runs as a regular user, so it covers the normal FreeBSD case. WASI Preview 1 is included because Wasmtime can return EBADF when reading a directory. In each case, the check lets fmt report “Is a directory.”

@limadog9
limadog9 force-pushed the fmt-read-without-metadata branch from 6c81de6 to e9a77aa Compare December 1, 2026 15:47

This branch has not been deployed

No deployments
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.

2 participants