<i>Windows: [file normalize] drops a component when parent enumeration is denied (non-junction case)</i>.
by
.
D 2026-07-12T19:32:36.081
J assignee nobody
J closer nobody
J cmimetype text/x-markdown
J comment ##\sSummary\r\n\r\nOn\sWindows,\sfile\snormalize\scan\ssilently\sremove\sa\spath\scomponent\swhen\sthe\scomplete\spath\sis\saccessible\sby\sits\sexact\sname,\sbut\san\sintermediate\sdirectory\smay\sbe\straversed\swithout\sbeing\senumerated.\r\n\r\nFor\sexample,\san\sexisting\spath\sending\sin:\r\n\r\n\s\s\s\sprofilecomponent/app/machteld.exe\r\n\r\nis\snormalized\sto:\r\n\r\n\s\s\s\sprofilecomponent//machteld.exe\r\n\r\nThe\sreturned\snormalized\spath\sno\slonger\snames\sthe\soriginal\sfile.\r\n\r\nThis\sis\sa\svalid\sWindows\sACL\sconfiguration.\sIt\salso\soccurs\swith\ssandboxed\sprocesses\sthat\sreceive\saccess\sto\sa\sknown\sdescendant\swithout\spermission\sto\senumerate\sits\sparent.\r\n\r\n##\sVersions\sand\senvironment\r\n\r\nRuntime\sreproduced\swith:\r\n\r\n-\sTcl\s9.0.3,\sregular\sWindows\sbuild\r\n-\sTcl\s8.6.17\r\n-\sWindows\s11\sPro\sx64\r\n-\sPowerShell\s5.1\r\n\r\nInspection\sof\swin/tclWinFile.c\sshows\sthe\ssame\srelevant\sbranch\sin\sTcl\s9.0.4:\r\n\r\n[Tcl\s9.0.4\ssource](https://github.com/tcltk/tcl/blob/core-9-0-4/win/tclWinFile.c#L2740-L2747)\r\n\r\nTk\sis\snot\sinvolved;\sthe\sissue\sis\sin\sTcl\score.\r\n\r\n##\sRelated\shistorical\sreports\r\n\r\nThis\sis\sclosely\srelated\sto\sTcl\sbugs\s[#4738\s/\s3092089](https://sourceforge.net/p/tcl/bugs/4738/)\sand\s[#5124\s/\s3587096](https://sourceforge.net/p/tcl/bugs/5124/).\sThose\sreports\sdocumented\sthe\ssame\scomponent\sloss—and\sthe\slatter\san\sinit.tcl\sstartup\sfailure—when\sdirectory\slisting\swas\sdenied\saround\sWindows\sjunctions.\sThey\swere\sclosed\sas\sfixed\sin\s2013\safter\sa\schange\sto\sreparse-point\saccess.\r\n\r\nThe\spresent\sreproducer\suses\sonly\sordinary\sdirectories,\snot\sjunctions\sor\sother\sreparse\spoints,\sand\sstill\striggers\sthe\sgeneric\sFindFirstFileW\sfailure\sbranch\sin\sTcl\s8.6.17\sand\s9.0.3.\sThe\ssame\sbranch\sremains\sin\sthe\s9.0.4\ssource.\sThis\stherefore\sappears\sto\sbe\sa\snon-junction\scase\sthat\sthe\s2013\sreparse-point\sfix\sdid\snot\scover.\r\n\r\n##\sReproducer\r\n\r\nThis\sscript\screates\sa\sunique\stemporary\sfixture,\sadds\sa\snon-inheriting\sListDirectory\sdenial\sonly\sto\sone\sfixture\sdirectory,\sruns\sTcl,\srestores\sthe\soriginal\sACL,\sand\sremoves\sthe\sfixture.\sIt\sdoes\snot\srequire\selevation.\sThe\stemporary\sfilesystem\smust\ssupport\sWindows\sACLs.\r\n\r\nSave\sit\sas\srepro.ps1\sand\spass\sthe\spath\sto\sa\sWindows\stclsh.\r\n\r\n\s\s\s\sparam(\r\n\s\s\s\s\s\s\s\s[Parameter(Mandatory\s=\s$true,\sPosition\s=\s0)]\r\n\s\s\s\s\s\s\s\s[string]\s$Tclsh\r\n\s\s\s\s)\r\n\r\n\s\s\s\s$ErrorActionPreference\s=\s'Stop'\r\n\s\s\s\s$root\s=\sJoin-Path\s$env:TEMP\s(\r\n\s\s\s\s\s\s\s\s'tcl-normalize-repro-'\s+\s[guid]::NewGuid().ToString('N')\r\n\s\s\s\s)\r\n\s\s\s\s$blocked\s=\sJoin-Path\s$root\s'profilecomponent'\r\n\s\s\s\s$child\s=\sJoin-Path\s$blocked\s'app'\r\n\s\s\s\s$target\s=\sJoin-Path\s$child\s'machteld.exe'\r\n\s\s\s\s$originalSddl\s=\s$null\r\n\s\s\s\s$aclChanged\s=\s$false\r\n\r\n\s\s\s\stry\s{\r\n\s\s\s\s\s\s\s\s[void][IO.Directory]::CreateDirectory($child)\r\n\s\s\s\s\s\s\s\s$created\s=\s[IO.File]::Create($target)\r\n\s\s\s\s\s\s\s\s$created.Dispose()\r\n\r\n\s\s\s\s\s\s\s\s$acl\s=\sGet-Acl\s-LiteralPath\s$blocked\r\n\s\s\s\s\s\s\s\s$originalSddl\s=\s$acl.Sddl\r\n\s\s\s\s\s\s\s\s$deny\s=\s[Security.AccessControl.FileSystemAccessRule]::new(\r\n\s\s\s\s\s\s\s\s\s\s\s\s[Security.Principal.WindowsIdentity]::GetCurrent().User,\r\n\s\s\s\s\s\s\s\s\s\s\s\s[Security.AccessControl.FileSystemRights]::ListDirectory,\r\n\s\s\s\s\s\s\s\s\s\s\s\s[Security.AccessControl.InheritanceFlags]::None,\r\n\s\s\s\s\s\s\s\s\s\s\s\s[Security.AccessControl.PropagationFlags]::None,\r\n\s\s\s\s\s\s\s\s\s\s\s\s[Security.AccessControl.AccessControlType]::Deny\r\n\s\s\s\s\s\s\s\s)\r\n\s\s\s\s\s\s\s\s[void]$acl.AddAccessRule($deny)\r\n\s\s\s\s\s\s\s\sSet-Acl\s-LiteralPath\s$blocked\s-AclObject\s$acl\r\n\s\s\s\s\s\s\s\s$aclChanged\s=\s$true\r\n\r\n\s\s\s\s\s\s\s\stry\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\s$stream\s=\s[IO.File]::Open(\r\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s$target,\r\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s[IO.FileMode]::Open,\r\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s[IO.FileAccess]::Read,\r\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s([IO.FileShare]::ReadWrite\s-bor\s[IO.FileShare]::Delete)\r\n\s\s\s\s\s\s\s\s\s\s\s\s)\r\n\s\s\s\s\s\s\s\s\s\s\s\s$stream.Dispose()\r\n\s\s\s\s\s\s\s\s\s\s\s\s'direct-exact-open=SUCCESS'\r\n\s\s\s\s\s\s\s\s}\scatch\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\s"direct-exact-open=FAILED:\s$($_.Exception.Message)"\r\n\s\s\s\s\s\s\s\s}\r\n\r\n\s\s\s\s\s\s\s\stry\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\s[void][IO.Directory]::GetFileSystemEntries($blocked)\r\n\s\s\s\s\s\s\s\s\s\s\s\s'parent-enumeration=UNEXPECTED-SUCCESS'\r\n\s\s\s\s\s\s\s\s}\scatch\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\s$errorObject\s=\s$_.Exception\r\n\s\s\s\s\s\s\s\s\s\s\s\sif\s($errorObject.InnerException)\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s$errorObject\s=\s$errorObject.InnerException\r\n\s\s\s\s\s\s\s\s\s\s\s\s}\r\n\s\s\s\s\s\s\s\s\s\s\s\s"parent-enumeration=$($errorObject.GetType().FullName)"\r\n\s\s\s\s\s\s\s\s}\r\n\r\n\s\s\s\s\s\s\s\s$env:TCL_NORMALIZE_REPRO_PATH\s=\s$target\r\n\r\n\s\s\s\s\s\s\s\s@'\r\n\s\s\s\sset\sp\s$::env(TCL_NORMALIZE_REPRO_PATH)\r\n\s\s\s\sset\sn\s[file\snormalize\s$p]\r\n\r\n\s\s\s\sputs\s"tcl=[info\spatchlevel]"\r\n\s\s\s\sputs\s"input=[string\smap\s{\\\s/}\s$p]"\r\n\s\s\s\sputs\s"input-exists=[file\sexists\s$p]"\r\n\s\s\s\sputs\s"normalized=$n"\r\n\s\s\s\sputs\s"normalized-exists=[file\sexists\s$n]"\r\n\s\s\s\s'@\s|\s&\s$Tclsh\r\n\s\s\s\s}\sfinally\s{\r\n\s\s\s\s\s\s\s\sRemove-Item\sEnv:TCL_NORMALIZE_REPRO_PATH\s-ErrorAction\sSilentlyContinue\r\n\r\n\s\s\s\s\s\s\s\sif\s($aclChanged)\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\s$restoredAcl\s=\s[Security.AccessControl.DirectorySecurity]::new()\r\n\s\s\s\s\s\s\s\s\s\s\s\s$restoredAcl.SetSecurityDescriptorSddlForm($originalSddl)\r\n\s\s\s\s\s\s\s\s\s\s\s\sSet-Acl\s-LiteralPath\s$blocked\s-AclObject\s$restoredAcl\r\n\s\s\s\s\s\s\s\s}\r\n\r\n\s\s\s\s\s\s\s\sif\s([IO.Directory]::Exists($root))\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\sRemove-Item\s-LiteralPath\s$root\s-Recurse\s-Force\r\n\s\s\s\s\s\s\s\s}\r\n\s\s\s\s}\r\n\r\nExample\sinvocation:\r\n\r\n\s\s\s\spowershell\s-NoProfile\s-File\s.\\repro.ps1\sC:\\path\\to\\tclsh90.exe\r\n\r\n##\sActual\sresult\r\n\r\nWith\sTcl\s9.0.3:\r\n\r\n\s\s\s\sdirect-exact-open=SUCCESS\r\n\s\s\s\sparent-enumeration=System.UnauthorizedAccessException\r\n\s\s\s\stcl=9.0.3\r\n\s\s\s\sinput=C:/.../profilecomponent/app/machteld.exe\r\n\s\s\s\sinput-exists=1\r\n\s\s\s\snormalized=C:/.../profilecomponent//machteld.exe\r\n\s\s\s\snormalized-exists=0\r\n\r\nThe\ssame\scomponent\sloss\swas\sreproduced\swith\sTcl\s8.6.17.\r\n\r\n##\sExpected\sresult\r\n\r\nBecause\sthe\sexact\spath\sexists\sand\sis\saccessible,\snormalization\sshould\sretain\severy\scomponent:\r\n\r\n\s\s\s\snormalized=C:/.../profilecomponent/app/machteld.exe\r\n\s\s\s\snormalized-exists=1\r\n\r\nIf\sTcl\scannot\sdiscover\sthe\scanonical\sspelling\sof\sapp\swithout\senumerating\sits\sparent,\spreserving\sthe\ssupplied\sspelling\swould\sbe\spreferable\sto\sdeleting\sthe\scomponent.\sReturning\san\serror\swould\salso\spreserve\spath\sintegrity\sbetter\sthan\sreturning\sa\sdifferent\spath.\r\n\r\n##\sApparent\scause\r\n\r\nIn\sTclpObjNormalizePath()\sin\swin/tclWinFile.c,\sGetFileAttributesExW()\sfirst\sestablishes\sthat\sthe\sexact\spath\sprefix\sexists.\sTcl\sthen\scalls\sFindFirstFileW()\sto\sobtain\sthe\sfilesystem\sspelling\sof\sthe\scurrent\scomponent.\r\n\r\nA\sdirect\sWin32\sprobe\sagainst\sthe\ssame\sACL\sfixture\sconfirms:\r\n\r\n-\sthe\sexact\schild\sfile\scan\sbe\sopened;\r\n-\sGetFileAttributesExW(.../profilecomponent/app)\sreturns\sTRUE;\r\n-\sFindFirstFileW(.../profilecomponent/app)\sreturns\sINVALID_HANDLE_VALUE\swith\sGetLastError()\sequal\sto\s5\s(ERROR_ACCESS_DENIED).\r\n\r\nThe\sINVALID_HANDLE_VALUE\sbranch\sdoes\snot\sinspect\sGetLastError().\sIt\sassumes\sthe\sfailure\sis\sthe\sroot-directory\scase\sdescribed\sby\sits\scomment\sand\sappends\sonly\sa\sslash:\r\n\r\n\s\s\s\shandle\s=\sFindFirstFileW((WCHAR\s*)\snativePath,\s&fData);\r\n\s\s\s\sif\s(handle\s==\sINVALID_HANDLE_VALUE)\s{\r\n\s\s\s\s\s\s\s\s/*\r\n\s\s\s\s\s\s\s\s\s*\sThis\sis\susually\sthe\s'/'\sin\s'c:/'\sat\send\sof\sstring.\r\n\s\s\s\s\s\s\s\s\s*/\r\n\s\s\s\s\s\s\s\sTcl_DStringAppend(&dsNorm,\s(const\schar\s*)\sL"/",\r\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\ssizeof(WCHAR));\r\n\s\s\s\s}\r\n\r\nFor\sa\snormal\scomponent\ssuch\sas\sapp,\sthis\ssilently\sreplaces\sthe\scomponent\swith\sa\sslash.\r\n\r\n##\sImpact\r\n\r\nThis\sis\snot\slimited\sto\sartificial\sACLs.\sIt\scan\soccur\sunder\sapplication\ssandboxes\sand\scapability-based\saccess\sarrangements\swhere\sa\sprocess\scan\sopen\sa\sknown\sfile\sbut\scannot\slist\sone\sof\sits\sancestors.\r\n\r\nIt\swas\sencountered\swith\sa\sstandalone\sTcl/Tk\sapplication\slocated\sbelow\sa\srestricted\suser-profile\sdirectory.\sTcl\snormalized\sthe\sexecutable\spath\sbefore\sreopening\sit\sfor\sZIPFS\smounting.\sThe\scorrupted\spath\sprevented\sthe\sembedded\sTcl\slibrary\sfrom\sbeing\smounted,\sso\sstartup\ssubsequently\sfailed\swhile\slooking\sfor\sinit.tcl.\r\n\r\nMore\sgenerally,\sfile\snormalize\scan\sreturn\sa\snonexistent\spath\sfor\san\sexisting,\saccessible\sfile.\r\n\r\n##\sPossible\sconservative\sfix\r\n\r\nFor\sa\snon-root\scomponent\swhose\sexistence\swas\salready\sestablished\sby\sGetFileAttributesExW(),\sif\sFindFirstFileW()\scannot\sretrieve\sits\scanonical\sspelling,\sone\sconservative\sresponse\swould\sbe\seither:\r\n\r\n-\sretain\sthe\scomponent\sspelling\sfrom\sthe\sinput\spath;\sor\r\n-\sreturn\sa\sTcl\serror.\r\n\r\nThe\sdrive\sor\sUNC\sroot\scase\scan\sbe\srecognized\sstructurally.\sFor\sother\sFindFirstFileW()\sfailures,\sinspecting\sGetLastError()\sand\spreserving\sthe\ssupplied\scomponent\sspelling\sfor\saccess-related\sfailures—or\sreturning\san\serror—would\savoid\ssilently\sdeleting\sthe\scomponent.\sA\snot-found\sor\srace\scondition\smay\sneed\sseparate\streatment.\r\n\r\nA\sWindows\sregression\stest\susing\sa\snon-inheriting\sListDirectory\sdenial\swould\scover\sthis\sconfiguration.\r\n\r\nReported\sby\sVincent\sVercauteren.
J foundin 9.0.3\s(also\s8.6.17;\scode\sunchanged\sin\s9.0.4)
J is_private 0
J login anafalanx
J priority 5\sMedium
J private_contact 77b422bfd65c247cc82396c9c83d9d4c89345daf
J resolution None
J severity Important
J status Open
J submitter anafalanx
J subsystem 36.\sPathname\sManagement
J title Windows:\s[file\snormalize]\sdrops\sa\scomponent\swhen\sparent\senumeration\sis\sdenied\s(non-junction\scase)
J type Bug
K d40d8db3fb7f69b66c624caf6b3b4f3d74fbbab4
U anafalanx
Z be685934101d45d3ba96bd8fc4d8ac08