Skip to content

[Bug] Characters in paths permitted by Linux (usable via BTRFS) that aren't permitted by PathCleanupSpec become $Null or invalid codepoints. #13166

Open
@RokeJulianLockhart

Description

@RokeJulianLockhart

Windows Version

10.0.26120.0

WSL Version

2.6.0.0

Are you using WSL 1 or WSL 2?

  1. WSL 2

  2. WSL 1

Kernel Version

uname -a

uname -a returns:

Linux version 6.6.87.2-microsoft-standard-WSL2 (root@439a258ad544) (gcc (GCC) 11.2.0, GNU ld (GNU Binutils) 2.37) #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025

Distro Version

lsb-release

LSB has been long deprecated, so it isn't available outside of Debian derivatives. Consequently, etc/os-release returns cpe:/o:fedoraproject:fedora:39 and HOME_URL="https://github.com/WhitewaterFoundry/Fedora-Remix-for-WSL".

Other Software

microsoft/terminal#19058 (comment) includes this information (from an unrelated BR about MAX_PATH):

  1. Obviously, explorer.exe applies:

    1. #!/usr/bin/env pwsh
      #Requires -PSEdition 'Core'
      If ($IsWindows)
      {
      	Get-Item -Path (
      		Get-Command 'explorer' | `
      		Select-Object -ExpandProperty 'Source'
      	) | `
      	Select-Object -ExpandProperty 'VersionInfo' | `
      	Format-List
      }

      1

    2. OriginalFilename  : EXPLORER.EXE.MUI
      FileDescription   : Windows Explorer
      ProductName       : Microsoft® Windows® Operating System
      Comments          :
      CompanyName       : Microsoft Corporation
      FileName          : C:\Windows\explorer.exe
      FileVersion       : 10.0.26100.4441 (WinBuild.160101.0800)
      ProductVersion    : 10.0.26100.4441
      IsDebug           : False
      IsPatched         : False
      IsPreRelease      : False
      IsPrivateBuild    : False
      IsSpecialBuild    : False
      Language          : English (United Kingdom)
      LegalCopyright    : © Microsoft Corporation. All rights reserved.
      LegalTrademarks   :
      PrivateBuild      :
      SpecialBuild      :
      FileVersionRaw    : 10.0.26100.2415
      ProductVersionRaw : 10.0.26100.2415
  2. However, Bug: The first file and directory names to exceed the 260-character MAX_PATH limit appear truncated. files-community/Files#17133 (comment) could also apply here:

    1. #!/usr/bin/env pwsh
      Get-AppxPackage FilesPreview
    2. Publisher         : CN=Yair Aichenbaum, O=Yair Aichenbaum, L=Baltimore, S=Maryland, C=US
      ResourceId        :
      InstallLocation   : C:\Program Files\WindowsApps\FilesPreview_3.9.10.0_x64__1y0xx7n9077q4
      IsFramework       : False
      IsResourcePackage : False
      IsBundle          : False
      IsDevelopmentMode : False
      NonRemovable      : False
      Dependencies      : {Microsoft.WindowsAppRuntime.1.7_7000.522.1444.0_x64__8wekyb3d8bbwe,
                          Microsoft.VCLibs.140.00.UWPDesktop_14.0.33728.0_x64__8wekyb3d8bbwe,
                          Microsoft.VCLibs.140.00_14.0.33519.0_x64__8wekyb3d8bbwe}
      IsPartiallyStaged : False
      SignatureKind     : Developer
      Status            : Ok

Repro Steps

As files-community/Files#17205 (comment) explains:

  1. Using a real Linux OS, in a BTRFS filesystem, create a path longer than MAX_PATH that contains tab characters.

  2. On the host, execute the undermentioned:

    #!/usr/bin/env pwsh
    #Requires -PSEdition Core
    If ($IsWindows) { wmic diskdrive list brief }

    2

  3. When the correct filesystem has been identified:

    #!/usr/bin/env pwsh
    #Requires -PSEdition Core
    If ($IsWindows) { sudo wsl --mount \\.\PHYSICALDRIVE1 --bare }
  4. Likewise, on WSL:

    #!/usr/bin/env sh
    sudo lsblk -o NAME,FSTYPE,FSVER,FSAVAIL,MOUNTPOINTS

    This shall return output similar to the undermentioned:

    NAME   FSTYPE FSVER FSAVAIL MOUNTPOINTS
    sda    ext4   1.0
    sdb    ext4   1.0
    sdc    swap   1             [SWAP]
    sdd    ext4   1.0    954.6G /mnt/wslg/distro
                                /
    sde
    ├─sde1 vfat   FAT32
    ├─sde2 ext4   1.0
    ├─sde3 ext4   1.0
    └─sde4 btrfs           1.2T /mnt/rjlb/fedora

    Utilise the output to confirm that the device has been mounted into wsl, then set its path as $dev_id, and define a mount point at $path.

  5. When the correct filesystem has been identified:

    #!/usr/bin/env sh
    sudo mkdir /mnt/$path && \
    sudo mount -t btrfs -o ro /dev/$dev_id /mnt/$path

    3

Expected Behavior

Consumers should be provided with escaped or verbatim representations of the file paths.

Actual Behavior

Most importantly, explorer.exe (and others, like FilesCommunity.Files, hence the report here, rather than at Feedback Hub) render replacement characters for invalid codepoints where the tabs should be. WSL shouldn't ever replace valid UTF codepoints with invalid codepoints. UNICODE doesn't ever permit that.

Additionally, IDK whether it's due to being past MAX_PATH or the filenames themselves, but if I open a wt.exe instance (via FilesPreview, because of microsoft/terminal#19058 (comment)) at Microsoft.PowerShell.Core\FileSystem::\\wsl.localhost\fedoraremix\mnt\rjlb_data\@{'Name'='Entities'}#.dir\@{'Status'='Commenced'; 'Name'='In Use'}#.dir\@{'Person'='Beedell'; 'Identifier'='S21AIB'}#.dir\@{'Name'='Entity-Specific'}#.dir\@{'Person'='Roke'; 'Identifier'='S1EV2L'}#.dir\@{'Name'='Temporary'}#.dir, then run:

  1. tree spawns in a new OpenConsole window (which it never does elsewhere), then crashes (per WinDbg):

    C:\__w\1\s\src\server\ConDrvDeviceComm.cpp(147)\OpenConsole.exe!00007FF7CF792894: (caller: 00007FF7CF7925C7) ReturnHr(1) tid(6020) 800700E9 No process is on the other end of the pipe.
    ntdll!NtTerminateProcess+0x14:
    00007ffc`1f7dfc34 c3              ret
    0:007> k
     # Child-SP          RetAddr               Call Site
    00 0000002b`3a7ffc38 00007ffc`1f75fd8e     ntdll!NtTerminateProcess+0x14
    01 0000002b`3a7ffc40 00007ffc`1e9218ab     ntdll!RtlExitUserProcess+0x11e
    02 0000002b`3a7ffc70 00007ff7`cf70a4b9     KERNEL32!ExitProcessImplementation+0xb
    03 0000002b`3a7ffca0 00007ff7`cf72eb47     OpenConsole+0xa4b9
    04 0000002b`3a7ffcd0 00007ffc`1e90e8d7     OpenConsole+0x2eb47
    05 0000002b`3a7fff50 00007ffc`1f75fbcc     KERNEL32!BaseThreadInitThunk+0x17
    06 0000002b`3a7fff80 00000000`00000000     ntdll!RtlUserThreadStart+0x2c

    Originally, I thought it was designed to close on completion, but tree, in all other circumstances, doesn't spawn a new window. It wouldn't make much sense for a standalone window, anyway. (I've a .dump /ma, if of use, although IDK whether that would probably be best provided to the Windows Terminal team.)

  2. Per When Get-ChildItem's $PWD contains children whose names are comprised of characters disallowed by PathCleanupSpec, it renders them as $Null. PowerShell/PowerShell#25680 (comment), Get-ChildItem, no names are returned, despite Windows disallowing $Null filenames:

    PS Microsoft.PowerShell.Core\FileSystem::\\wsl.localhost\fedoraremix\mnt\rjlb_data\@{'Name'='Entities'}#.dir\@{'Status'='Commenced'; 'Name'='In Use'}#.dir\@{'Person'='Beedell'; 'Identifier'='S21AIB'}#.dir\@{'Name'='Entity-Specific'}#.dir\@{'Person'='Roke'; 'Identifier'='S1EV2L'}#.dir\@{'Name'='Temporary'}#.dir> ls
    
        Directory: \\wsl.localhost\fedoraremix\mnt\rjlb_data\@{'Name'='Entities'}#.dir\@{'Status'='Commenced'; 'Name'='In
    Use'}#.dir\@{'Person'='Beedell'; 'Identifier'='S21AIB'}#.dir\@{'Name'='Entity-Specific'}#.dir\@{'Person'='Roke';
    'Identifier'='S1EV2L'}#.dir\@{'Name'='Temporary'}#.dir
    
    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    d----          2024-04-08    13:30
    d----          2023-09-25    23:51
    d----          2023-03-21    16:30
    d----          2023-12-16    03:10
    d----          2023-04-15    19:55
    d----          2022-10-23    22:23
    d----          2023-09-22    22:00
    d----          2023-09-22    22:01
    -----          2022-06-23    14:26     1011594814
    -----          2022-05-12    23:15         144430
    -----          2022-07-01    00:20            557
    -----          2022-01-07    00:50         373962
    -----          2023-09-22    22:02             67
    -----          2021-03-19    14:41          65647 @{'Status'='Completed'; 'Name'='Instagram Illustration';
                                                      'Identifier'='S1G0ZM'}#.JPEG
    -----          2022-05-12    23:15           3296
    -----          2022-05-26    13:21         440127
    -----          2022-05-26    13:25          18313
    -----          2022-06-30    09:13         141148
    -----          2022-06-30    09:14         250847
    -----          2022-07-01    17:35          35892
    -----          2022-07-02    01:14         165810
    -----          2022-07-02    01:14          48157
    -----          2022-07-03    14:10         376541
    -----          2021-12-24    15:18           9367
    -----          2022-03-23    14:59          25051
    -----          2023-07-04    23:41          34374

Heck, I shan't be surprised if this relates to microsoft/WinDbg-Feedback#248 (comment) too.

Diagnostic Logs

I've attempted to adhere to github.com/microsoft/WSL/blob/769e508a341ad45dd24ee0794e75a15a6d211986/CONTRIBUTING.md?plain=1#L104C1-L112C65, but it merely hangs:

Image

Footnotes

  1. stackoverflow.com/revisions/45517267/4

  2. blog.bryanroessler.com/2020-12-14-btrfs-on-wsl2/

  3. askubuntu.com/revisions/296342/3

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions