Skip to content

OperationStopped: Incorrect function when running an exe from a mounted ISO #16293

Closed

Description

@jeanga

Prerequisites

Steps to reproduce

My repro steps:

But I do not think this is linked to the EWDK but the fact I'm running a exe from a mounted iso.
(was running just fine with 7.1.5 or the previous 7.2 preview)

Expected behavior

Successfully run msbuild.exe

Actual behavior

OperationStopped: Incorrect function. : 'E:\Program Files\Microsoft Visual Studio\2019\BuildTools\\MSBuild\Current\Bin\MSBuild.exe'

Error details

Exception             :
    Type       : System.IO.IOException
    TargetSite :
        Name          : GetImmediateLinkTarget
        DeclaringType : System.IO.FileSystem, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=7cec85d7bea7798e
        MemberType    : Method
        Module        : System.Private.CoreLib.dll
    Message    : Incorrect function. : 'E:\Program Files\Microsoft Visual
Studio\2019\BuildTools\\MSBuild\Current\Bin\MSBuild.exe'
    Data       : System.Collections.ListDictionaryInternal
    Source     : System.Private.CoreLib
    HResult    : -2147024895
    StackTrace :
   at System.IO.FileSystem.GetImmediateLinkTarget(String linkPath, Boolean isDirectory, Boolean throwOnError, Boolean
returnFullPath)
   at System.IO.FileSystem.ResolveLinkTarget(String linkPath, Boolean returnFinalTarget, Boolean isDirectory)
   at System.IO.File.ResolveLinkTarget(String linkPath, Boolean returnFinalTarget)
   at System.Management.Automation.NativeCommandProcessor.IsWindowsApplication(String fileName)
   at System.Management.Automation.NativeCommandProcessor.InitNativeProcess()
   at System.Management.Automation.NativeCommandProcessor.Prepare(IDictionary psDefaultParameterValues)
   at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
   at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput,
CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections,
FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo          : OperationStopped: (:) [], IOException
FullyQualifiedErrorId : System.IO.IOException
InvocationInfo        :
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : -1
    Line             : msbuild.exe
    PositionMessage  : At line:1 char:1
                       + msbuild.exe
                       + ~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.0-rc.1
PSEdition                      Core
GitCommitId                    7.2.0-rc.1
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

Activity

  1. added
    Needs-Triage
    on Oct 22, 2021
  2. changed the title [-]OperationStopped: Incorrect function when running an exe from a mounter ISO (i.e. Enterprise-WDK)[/-] [+]OperationStopped: Incorrect function when running an exe from a mounted ISO[/+] on Oct 22, 2021
  3. added
    Area-FileSystem-Provider
    Issue-Bug
    on Oct 22, 2021
  4. iSazonov commented on Oct 22, 2021

    @iSazonov
    Collaborator

    Jean Gautier (@jeanga) Please open new issue in .Net Runtime repository and link that issue.

    Unbelievable, I just prepared a performance fix for this code which just gets rid of this ResolveLinkTarget and fixes this problem in PowerShell :-)

  5. ghost added
    In-PR
    on Oct 22, 2021
  6. iSazonov commented on Oct 23, 2021

    @iSazonov
    Collaborator

    After further study, I think this is purely a PowerShell problem, since it is correct that System.IO.File.ResolveLinkTarget() causes an IO exception for file systems (ISO, FAT, ...) that does not support reparse points.

  7. jborean93 commented on Oct 23, 2021

    @jborean93
    Collaborator

    Heh I thought we fixed this as per #13605 but looks like it regressed again. Seems like #16295 (or some other PR) should include some tests for this specific scenario to stop it from happening once again.

  8. iSazonov commented on Oct 25, 2021

    @iSazonov
    Collaborator

    To add a test we need to create an ISO file with exe file on the fly.

  9. jborean93 commented on Oct 25, 2021

    @jborean93
    Collaborator

    Not necessarily, you just need a file system that doesn't support reparse points. I see 2 easy-ish ways to do this

    You can the use Mount-DiskImage to mount either the ISO or VHDX for the test and try and run the executable placed in that volume.

    The VHDX scenario is simple to replicate

    $vhdx = 'C:\temp\vhdx\my.vhdx'
    if (Test-Path -Path $vhdx) {
        Remove-item -Path $vhdx -Force
    }
    
    Set-Content create_vhdx.txt @"
    create vdisk file="$vhdx" maximum=20 type=fixed
    select vdisk file="$vhdx"
    attach vdisk
    convert mbr
    create partition primary
    format fs=fat
    assign letter="T"
    detach vdisk
    "@
    
    diskpart.exe /s (Get-Item .\create_vhdx.txt).FullName
    Mount-DiskImage -ImagePath $vhdx | Out-Null
    
    # Copy binary to T:\ and do test
    Copy-Item C:\Windows\System32\whoami.exe T:\whoami.exe
    T:\whoami.exe
    
    Dismount-DiskImage -ImagePath $vhdx

    To avoid diskpart you could use PInvoke to call CreateVirtualDisk, creating the partition and formatting should also be doable using various PowerShell cmdlets as well if you wanted to avoid diskpart.exe altogether

    I have verified the VHDX example also excises this problematic code as the FAT format doesn't support reparse points.

  10. iSazonov commented on Oct 25, 2021

    @iSazonov
    Collaborator

    Jordan Borean (@jborean93) Thanks! I added the test.

  11. jborean93 commented on Oct 26, 2021

    @jborean93
    Collaborator

    Thanks Ilya (@iSazonov) appreciate adding the test, should hopefully stop this from recurring in the future!

  12. ghost removed
    Needs-Triage
    on Oct 30, 2021
  13. ghost removed
    In-PR
    on Nov 3, 2021
  14. ghost added
    Resolution-Fixed
    on Nov 3, 2021
  15. jeanga commented on Nov 8, 2021

    @jeanga
    Author

    Verified fixed! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-ProviderIssue-BugResolution-Fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions