vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

PSReadLine crash trying to assign [Net.ServicePointManager]::SecurityProtocol on MacOS

Open AnotherLuckyGuy opened this issue 1 year ago • 2 comments

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest released version
  • [X] Search the existing issues, especially the pinned issues.

Exception report

### Exception

 

System.BadImageFormatException: An attempt was made to load a program with an incorrect format.

(0x8007000B)

   at System.Reflection.RuntimeAssembly.<InternalLoad>g____PInvoke|49_0(NativeAssemblyNameParts* __pAssemblyNameParts_native, ObjectHandleOnStack __requestingAssembly_native, StackCrawlMarkHandle __stackMark_native, Int32 __throwOnFileNotFound_native, ObjectHandleOnStack __assemblyLoadContext_native, ObjectHandleOnStack __retAssembly_native)

   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)

   at System.Reflection.Assembly.Load(AssemblyName assemblyRef)

   at System.Management.Automation.PowerShellAssemblyLoadContext.GetTrustedPlatformAssembly(String tpaStrongName)

   at System.Management.Automation.PowerShellAssemblyLoadContext.GetAssembly(String namespaceQualifiedTypeName)

   at System.Management.Automation.ClrFacade.GetAssemblies(TypeResolutionState typeResolutionState, TypeName typeName)

   at System.Management.Automation.Language.TypeResolver.ResolveTypeNameWithContext(TypeName typeName, Exception& exception, Assembly[] assemblies, TypeResolutionState typeResolutionState)

   at System.Management.Automation.Language.SymbolResolver.VisitTypeName(TypeName typeName, Int32 genericArgumentCount, Boolean isAttribute)

   at System.Management.Automation.Language.SymbolResolver.VisitTypeExpression(TypeExpressionAst typeExpressionAst)

   at System.Management.Automation.Language.TypeExpressionAst.InternalVisit(AstVisitor visitor)

   at System.Management.Automation.Language.CommandExpressionAst.InternalVisit(AstVisitor visitor)

   at System.Management.Automation.Language.PipelineAst.InternalVisit(AstVisitor visitor)

   at System.Management.Automation.Language.NamedBlockAst.InternalVisit(AstVisitor visitor)

   at System.Management.Automation.Language.ScriptBlockAst.InternalVisit(AstVisitor visitor)

   at System.Management.Automation.Language.Parser.ParseTask(String fileName, String input, List`1 tokenList, Boolean recursed, ParseMode parseMode)

   at System.Management.Automation.Language.Parser.Parse(String fileName, String input, List`1 tokenList, ParseError[]& errors, ParseMode parseMode)

   at System.Management.Automation.Language.Parser.ParseInput(String input, String fileName, Token[]& tokens, ParseError[]& errors)

 

 

~/scripts> An error occurred while running the REPL loop:                                                                                                                        

System.Management.Automation.ParseException: Unrecoverable error in PowerShell.

---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format.

(0x8007000B)

   at System.Reflection.RuntimeAssembly.<InternalLoad>g____PInvoke|49_0(NativeAssemblyNameParts* __pAssemblyNameParts_native, ObjectHandleOnStack __requestingAssembly_native, StackCrawlMarkHandle __stackMark_native, Int32 __throwOnFileNotFound_native, ObjectHandleOnStack __assemblyLoadContext_native, ObjectHandleOnStack __retAssembly_native)

   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)

   at System.Reflection.Assembly.Load(AssemblyName assemblyRef)

   at System.Management.Automation.PowerShellAssemblyLoadContext.GetTrustedPlatformAssembly(String tpaStrongName)

   at System.Management.Automation.PowerShellAssemblyLoadContext.GetAssembly(String namespaceQualifiedTypeName)

   at System.Management.Automation.ClrFacade.GetAssemblies(TypeResolutionState typeResolutionState, TypeName typeName)

   at System.Management.Automation.Language.TypeResolver.ResolveTypeNameWithContext(TypeName typeName, Exception& exception, Assembly[] assemblies, TypeResolutionState typeResolutionState)

   at System.Management.Automation.Language.SymbolResolver.VisitTypeName(TypeName typeName, Int32 genericArgumentCount, Boolean isAttribute)

   at System.Management.Automation.Language.SymbolResolver.VisitTypeExpression(TypeExpressionAst typeExpressionAst)

   at System.Management.Automation.Language.TypeExpressionAst.InternalVisit(AstVisitor visitor)

   at System.Management.Automation.Language.CommandExpressionAst.InternalVisit(AstVisitor visitor)

   at System.Management.Automation.Language.PipelineAst.InternalVisit(AstVisitor visitor)

   at System.Management.Automation.Language.NamedBlockAst.InternalVisit(AstVisitor visitor)

   at System.Management.Automation.Language.ScriptBlockAst.InternalVisit(AstVisitor visitor)

   at System.Management.Automation.Language.Parser.ParseTask(String fileName, String input, List`1 tokenList, Boolean recursed, ParseMode parseMode)

   at System.Management.Automation.Language.Parser.Parse(String fileName, String input, List`1 tokenList, ParseError[]& errors, ParseMode parseMode)

   at System.Management.Automation.Language.Parser.ParseInput(String input, String fileName, Token[]& tokens, ParseError[]& errors)

   --- End of inner exception stack trace ---

   at System.Management.Automation.Language.Parser.ParseInput(String input, String fileName, Token[]& tokens, ParseError[]& errors)

   at Microsoft.PowerShell.PSConsoleReadLine.GenerateRender(String defaultColor)

   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()

   at Microsoft.PowerShell.PSConsoleReadLine.Insert(String s)

   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)

   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Console.PsrlReadLine.InvokePSReadLine(CancellationToken cancellationToken) in C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Console\PsrlReadLine.cs:line 48

   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousDelegateTask`1.Run(CancellationToken cancellationToken) in C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousDelegateTask.cs:line 63

   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousTask`1.ExecuteSynchronously(CancellationToken executorCancellationToken) in C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousTask.cs:line 77

--- End of stack trace from previous location ---

   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousTask`1.get_Result() in C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousTask.cs:line 55

   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.InvokeDelegate[TResult](String representation, ExecutionOptions executionOptions, Func`2 func, CancellationToken cancellationToken) in C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 526

   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Console.PsrlReadLine.ReadLine(CancellationToken cancellationToken) in C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Console\PsrlReadLine.cs:line 35

   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.InvokeReadLine(CancellationToken cancellationToken) in C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 1064

   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.DoOneRepl(CancellationToken cancellationToken) in C:\__w\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 963

Screenshot

not available.

Environment data

### Environment

PSReadLine: 2.4.0-beta0+923a890f2e7ea10465f3a80a2bc030121a1c2f68

PowerShell: 2024.2.2

OS: Darwin 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000

BufferWidth: 178

BufferHeight: 38

 

Last 200 Keys:

 

Backspace Backspace Backspace Backspace Backspace [ N e t . S e r v i c e P o i n t M a n a g e r ] : : S e c u r i t y P r o t o c o l Spacebar = Spacebar [ N e t . S e c u r i t y P r o t o c o l T y p e ] : : T l s 1 2 Spacebar - b o r Spacebar [ N e t . S e c u r i t y P r o t o c o l T y p e ] : : T l s 1 3 Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace [ N e t . S e r v i c e P o i n t M a n a g e r ] Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace [ N e t . S e r v i c e P o i n t

Steps to reproduce

Try to execute the following on MacOS with PS 7.4.5: [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13

Expected behavior

Not crashing

Actual behavior

PSReadline spits out an exception

AnotherLuckyGuy avatar Sep 23 '24 21:09 AnotherLuckyGuy

Thanks for submitting! Hmm that's a really odd exception for what you're experiencing. I see this was transferred from PSReadline, does it only reproduce in vscode?

JustinGrote avatar Sep 25 '24 15:09 JustinGrote

No, occurred from the terminal as well. Strangely when I open a new terminal session I can execute the command without issue. In fact it's been in my $profile for a long time. However I had this crash occur both within vscode and the terminal while I was working on a program. I believe something I was running or something I'm doing at the command line gets the PSReadline module in a bad state that then makes it vulnerable to this failure. I'm just not sure what exactly but if I can figure it out, I'll add more to the defect.

AnotherLuckyGuy avatar Sep 25 '24 20:09 AnotherLuckyGuy