Skip to content

[paths] On-disk NUL.txt handled three different ways by cat/grep/sed (device vs file depends on path tier) #1333

Closed

Description

@caomengxuan666

Summary

A real on-disk file whose name is a DOS reserved name with an extension (e.g. NUL.txt) is handled three different ways by three commands in the same build — the layers disagree about what the operand is.

Evidence (harness under Wine, file NUL.txt with content real-content created on disk; two runs)

  • cat NUL.txt → cat: NUL.txt: No such file or directory, rc1 (the extended-path open fails).
  • grep -c real NUL.txt → prints 0, rc1 (grep opened the NUL device: empty stream, no match).
  • sed -n /hit/p NUL.txt (device semantics) → empty output, rc0 (also read the device).
  • GNU on an ordinary file of that name: prints/matches the content, rc0 (the name is a legal filename on the host FS in the oracle fixture).

Source

src/utils/native_path.cppm resolve_pseudo_device_w/is_dos_device_name_w (~L698-772): device detection matches only the exact whole operand (NUL), never NUL.txt/NUL:-style forms; the extended-path layer lifts device parsing on real Windows (\?\ prefix), while normalize/raw layers hit the device namespace. Which behavior a user gets depends on which tier the command uses.

Caveat

Reproduced under Wine; Wine's device emulation may differ from native Windows in which tier "wins". The code-level inconsistency (exact-match-only device table + tier disagreement) is platform-independent — confirm the native-Windows outcome per tier when fixing, and make all tiers agree: an on-disk NUL.txt should be one thing everywhere (and a bare NUL should stay the device everywhere).

Regression seed

  • cat NUL.txt, grep -c x NUL.txt, sed -n p NUL.txt on an on-disk NUL.txt → one consistent, documented behavior across all three; cat NUL still reads the device (empty, rc0).

Found by the full-audit (Windows minefield sweep). Related: #1297 (on-disk dir named NUL undeletable) covers the bare-name dir case; this issue is the extension-form + cross-command consistency.

Activity

  1. added
    bug
    compat-gap
    on Oct 26, 2026
  2. added a commit that references this issue on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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