Skip to content

[paths] Trailing dot/space operands silently hit the wrong file in normalize/raw path tiers (sed reads 'name' for 'name.'; sed -i overwrites the wrong file) #1332

Closed

Description

@caomengxuan666

Summary

Operands whose final component ends in a dot or space are silently resolved to the wrong file by commands whose path layer only normalizes (or passes the path raw): the Win32 DOS path rules strip the trailing dot/space, so the command reads — or worse, overwrites — the sibling file without the suffix. Commands on the extended-path layer are immune; the layers disagree, so behavior differs per command for the same operand.

Evidence (harness vs GNU, identical fixtures, post-state compared; two runs)

Fixture contains BOTH files: name (content B) and name. (content A).

  1. Read: sed -n p 'name.'
    • GNU: prints content A.
    • WinuxCmd: prints content B (read name), rc0, no diagnostic.
  2. Write via sed -i: sed -i s/B/C/ 'name.' (fixture: name=lineB, name.=lineC-pending...)
    precisely: files name (lineB) and name. (lineC); run sed -i 's/line/EDIT/' 'name.':
    • GNU post-state: name. edited, name untouched.
    • WinuxCmd post-state: name edited, name. untouched — the -i temp+rename chain lands on the stripped name. Silent data corruption of the wrong file.
  3. Control: grep and cat probes of the same read operand matched GNU in this harness — the fidelity differs per command/path layer (sed's normalize path loses the suffix; the extended-path commands keep it). cat 'name ' (trailing space) family is the same shape.

Source

src/utils/native_path.cppm: commands route operands through three tiers — extended (make_api_path_operand/to_extended_path[_preserving]: suffix preserved), normalize-only (suffix lost to DOS rules on open), raw CreateFile/std::filesystem (same loss). sed uses the normalize tier including for its -i temp/rename chain. The winmine audit counted 51 normalize-tier + 14 raw-tier commands with file operands vs 43 extended-tier; any normalize/raw command is exposed (sed proven for read+write).

Regression seed

  • Both sed cases with post-state assertions; extend the same fixture pair (name + name., name + name␣) across the normalize/raw-tier commands when fixing.

Found by the full-audit (Windows minefield sweep). Related to the fixed long-path work (#1288/#1293) but a different mechanism (suffix fidelity, not length).

Metadata

Metadata

Labels

bugcompat-gap

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions