Repository navigation
Description
What happens
In default physical mode, uutils checks path components and resolves symlinks,
but when it encounters .. it removes the preceding component without
verifying that it is a directory. Consequently, an existing regular file
followed by /.. is accepted, whereas GNU realpath reports Not a directory and glibc realpath(3) fails with ENOTDIR.
To reproduce, create a fresh temporary directory and a regular file on each
host, then run the installed realpath on the file followed by /..:
d=$(mktemp -d)
touch "$d/afile"
echo "Fixture: $d/afile"
LANG=C LC_ALL=C /usr/bin/realpath --version | head -1
LANG=C LC_ALL=C /usr/bin/realpath -- "$d/afile/.."
echo "exit=$?"Observed on Ubuntu 26.04.1 LTS, with realpath (uutils coreutils) 0.10.0
from the rust-coreutils package:
Fixture: /tmp/tmp.yQxWVzVZiv/afile
realpath (uutils coreutils) 0.10.0
/tmp/tmp.yQxWVzVZiv
exit=0Observed on Debian, with GNU coreutils 9.7 and a fresh regular-file fixture:
Fixture: /tmp/tmp.pCAEmXMGM5/afile
realpath (GNU coreutils) 9.7
realpath: /tmp/tmp.pCAEmXMGM5/afile/..: Not a directory
exit=1I have not tested against the latest GNU coreutils release.
I also reproduced the success on uutils main commit
9cc868bcab387842ea2fa7b8e85c76e05860c51f (current main on 2026-11-01),
built from source on a Debian 13 VM with rustc 1.99.1:
To reproduce with a main checkout and the fixture created above:
cargo build --locked --no-default-features --features realpath --bin coreutils
LANG=C LC_ALL=C ./target/debug/coreutils realpath -- "$d/afile/.."
echo "exit=$?"The recorded result was:
Built realpath version:
realpath (uutils coreutils) 0.13.0
Reproduction:
/home/agent/egl425-work/fixture
exit=0The input was /home/agent/egl425-work/fixture/afile/.., with afile a
regular file. The main-branch run used LANG=C LC_ALL=C. GNU
coreutils 9.7 on the same fixture reported Not a directory and exited 1.
On that main commit, realpath -L and realpath -e also exited 0. A separate
build including readlink likewise exited 0 for readlink -f and -e; GNU
9.7 exited 1 for both on the same input.
Why this seems unintended
- GNU
realpath -Lalso reportsNot a directoryforafile/..(exit 1),
so rejecting this input is not limited to physical mode. GNU-m, on the
other hand, intentionally permits components that are not directories. - The
uucore::fs::canonicalizerustdoc
saysMissingHandling::Normalbehaves likestd::fs::canonicalize. In
physical mode uutils accepts this input, while Rust's
std::fs::canonicalizedocumentation
specifies an error when a non-final component is not a directory. The
stated equivalence is not exact in other cases either:Normalpermits a
missing final component, whilestd::fs::canonicalizerequires it to exist.
Source pointer
In uucore::fs::canonicalize() (src/uucore/src/lib/features/fs.rs), the
physical-mode ParentDir branch pops the preceding component without checking
whether it resolves to a directory:
OwningComponent::ParentDir => {
result.pop();
}For afile/.., the metadata check on afile succeeds because it exists, and
the following .. pops it. I observed this with uutils 0.10.0 and with current
main at 9cc868bc (built from source on 2026-11-01); the same relevant code is
present in the 0.12.0 source.
Expected behavior and impact
In default mode, afile/.. should fail instead of printing the parent when
afile is a regular file. A caller can otherwise receive a successful
canonical path for an input spelling that the kernel cannot traverse because
an intermediate component is a regular file. We encountered this in a
fail-closed path check: uutils accepted the input where GNU realpath refused
it.
Activity
Martell0x1 commentedon Nov 2, 2026
working on this