Files
l c1ff6d0506 tests: a lexical path canonicaliser, checked against Path::Canonicalize
Groundwork for taking std::string out of IopBios. host_path -- the
check that keeps host: inside the ELF directory -- runs its input
through Path::Canonicalize, which removes "." and ".." without
touching the filesystem. That matters: the guest may be creating a
file that does not exist yet, so path_resolve_realpath is not a
substitute, both because it fails on missing files and because it
follows symlinks, which changes what the sandbox is comparing.

So the C replacement has to be lexical too, and it has to match. This
commit is the canonicaliser and the evidence that it does.

Writing it from first principles was not enough. The first version
passed a 22-case table I wrote from what canonicalisation obviously
means, and still disagreed with the reference six ways:

  '/'          reference yields "", not "/"
  '/..'        reference yields "", not "/"   -- the empty leading
               component of an absolute path is a real component, and
               ".." pops it
  '/a/../..'   likewise ""
  '\a\b'       reference leaves it alone; backslash is not a separator
               on POSIX, translating it is ToNativePath's job
  'a\b/c'      likewise
  '../../a'    reference yields "a"

Two of those change what the sandbox compares. The backslash one would
have altered path handling for exactly the guests clean_path exists
for.

The version here is a port of the reference algorithm rather than a
reimplementation of the idea, and it is checked both ways: the 22-case
table, and a differential against Path::Canonicalize over 200,000
randomly generated paths -- zero differences.

No production code changes yet. The IopBios conversion follows, and it
has to move hostRoot, host_path, clean_path and the ten call sites
together: converting hostRoot alone while host_path still takes a
const std::string& would create an implicit temporary at every call,
which is the bug this campaign already shipped once in
ChdFileReader::OpenOne.
2026-08-22 09:44:51 +02:00
..