-
Notifications
You must be signed in to change notification settings - Fork 237
Very Large String crashes PS Editor Services #582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'll look into this. I seem to only be able to repro when that string is a number. For example, take the input number:
If you wrap it in |
Update - still looking into this. Here's what I've found out. I'm pretty sure the issue exists here: I've got a repro in PowerShell: Add-Type -Path C:\Users\tyleonha\PowerShellEditorServices\src\PowerShellEditorServices\bin\Debug\net451\System.Management.Automation.dll
$in = "1234765123875213874521321543211283641982364198327461324987214987621349876321487621348761234987612398476129836124369817326498716432987164329876321498761432987698743213218746123987461432121423987321432141234123443522345234523452345234523452435234553524352345234523452345243523452345234523452345234524352435234524352345243524353" # Really long string that just contains a number
[System.Management.Automation.Language.Parser]::ParseInput($in, "C:\Users\tyleonha\Desktop\repro.ps1", [ref] $tokens, [ref] $parseErrors) Note at this point there is one item in
Continuing the example to the failure: Add-Type -Path C:\Users\tyleonha\PowerShellEditorServices\src\PowerShellEditorServices\bin\Debug\net451\Microsoft.PowerShell.EditorServices.dll
[Microsoft.PowerShell.EditorServices.ScriptRegion]::Create($parseErrors[0].Extent) This gives us: Exception calling "Create" with "1" argument(s): "Index and length must refer to a location within the string.
Parameter name: length"
At line:1 char:1
+ [Microsoft.PowerShell.EditorServices.ScriptRegion]::Create($parseErro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentOutOfRangeException Not the most useful error but I think it might have something to do with the @rkeithhill or @daviwil : do either of you guys have any thoughts? |
This is not something you'd expect but accessing the IScriptExtent.Text property generates an exception in this case. We should catch that exception but it seems like a bug in PowerShell to me. Of course, what string do we use for the Text property in this case? |
@rkeithhill on Windows PowerShell (W10) the Text property is null for me. The full extent:
I don't get any exception - are you seeing something else? |
PowerShell ignores exceptions from properties. You can see it if you call the getter directly with |
Yup. I was staring at the impl of ScriptRegion.Create in PSES and thinking WTF, there is no call to Substring in this method. That's when I realized it had to be one of IScriptExtent properties. Once I repro'd the error under the VS debugger, it became obvious it was the Text property. |
Thanks for that @SeeminglyScience 😄 So to figure out what Text should be, I used the string: In this case, Text = repro good case: $in = '$f = {'
[System.Management.Automation.Language.Parser]::ParseInput($in, "C:\Users\tyleonha\Desktop\repro.ps1", [ref] $tokens, [ref] $parseErrors) Note, at this point
And
Looks like we just need to catch that error. I'm guessing that when we access |
Started the Advent of Code 2017 challenge and pasted in the input string into a .ps1 editor windows.
This crashed Editor Services.
Was able to reproduce.
Input string: https://adventofcode.com/2017/day/1/input
Log
04/12/2017 17:33:37 [NORMAL] - Method "StartLogging" at line 144 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\EditorServicesHost.cs
04/12/2017 17:33:37 [NORMAL] - Method "StartLanguageService" at line 180 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\EditorServicesHost.cs
04/12/2017 17:33:37 [NORMAL] - Method "StartDebugService" at line 254 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\EditorServicesHost.cs
04/12/2017 17:33:37 [NORMAL] - Method "Initialize" at line 220 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
04/12/2017 17:33:37 [NORMAL] - Method "FindPSScriptAnalyzerModule" at line 354 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Analysis\AnalysisService.cs
04/12/2017 17:33:38 [NORMAL] - Method "Register" at line 36 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.VSCode\ComponentRegistration.cs
04/12/2017 17:33:38 [ERROR] - Method "DispatchMessage" at line 147 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageDispatcher.cs
04/12/2017 17:33:38 [ERROR] - Method "DispatchMessage" at line 147 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageDispatcher.cs
04/12/2017 17:33:38 [ERROR] - Method "OnListenTaskCompleted" at line 391 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\ProtocolEndpoint.cs
04/12/2017 17:33:38 [ERROR] - Method "ProtocolEndpoint_UnhandledException" at line 418 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\EditorServicesHost.cs
The text was updated successfully, but these errors were encountered: