Skip to content

Parsing an array with too many dimensions throws exception #16275

Description

@daxian-dbw

Prerequisites

Steps to reproduce

This was originally reported in PowerShell/PSReadLine#2923 by @HumanEquivalentUnit

Run the following script in pwsh:

[System.Management.Automation.Language.Parser]::ParseInput('[int[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]]', [ref]$null, [ref]$null)

Expected behavior

No exception thrown from `Parser.ParseInput`

Actual behavior

PS:3> $a = [System.Management.Automation.Language.Parser]::ParseInput('[int[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]]', [ref]$null, [ref]$null)
MethodInvocationException: Exception calling "ParseInput" with "3" argument(s): "Unrecoverable error in PowerShell."

Error details

PS:4> Get-Error

Exception             :
    Type           : System.Management.Automation.MethodInvocationException
    ErrorRecord    :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Exception calling "ParseInput" with "3" argument(s): "Unrecoverable error in PowerShell."
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : ParseException
        InvocationInfo        :
            ScriptLineNumber : 1
            OffsetInLine     : 1
            HistoryId        : -1
            Line             : $a = [System.Management.Automation.Language.Parser]::ParseInput('[int[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]]',
[ref]$null, [ref]$null)
            PositionMessage  : At line:1 char:1
                               + $a = [System.Management.Automation.Language.Parser]::ParseInput('[int …
                               + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    TargetSite     :
        Name          : ConvertToMethodInvocationException
        DeclaringType : System.Management.Automation.ExceptionHandlingOps, System.Management.Automation, Version=7.1.3.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    StackTrace     :
   at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName,
Int32 numArgs, MemberInfo memberInfo)
   at CallSite.Target(Closure , CallSite , Type , String , PSReference , PSReference )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at System.Management.Automation.Interpreter.DynamicInstruction`5.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
    Message        : Exception calling "ParseInput" with "3" argument(s): "Unrecoverable error in PowerShell."
    Data           : System.Collections.ListDictionaryInternal
    InnerException :
        Type           : System.Management.Automation.ParseException
        Message        : Unrecoverable error in PowerShell.
        ErrorRecord    :
            Exception             :
                Type    : System.Management.Automation.ParentContainsErrorRecordException
                Message : Unrecoverable error in PowerShell.
                HResult : -2146233087
            CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
            FullyQualifiedErrorId : Parse
        TargetSite     :
            Name          : ParseInput
            DeclaringType : System.Management.Automation.Language.Parser
            MemberType    : Method
            Module        : System.Management.Automation.dll
        StackTrace     :
   at System.Management.Automation.Language.Parser.ParseInput(String input, String fileName, Token[]& tokens, ParseError[]& errors)
   at CallSite.Target(Closure , CallSite , Type , String , PSReference , PSReference )
        InnerException :
            Type       : System.TypeLoadException
            Message    : 'System.Int32[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]' from assembly 'System.Private.CoreLib, Version=5.0.0.0, Culture=neutral,
PublicKeyToken=7cec85d7bea7798e' has too many dimensions.
            TypeName   : System.Int32[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]
            TargetSite :
                Name          : MakeArray
                DeclaringType : System.RuntimeTypeHandle
                MemberType    : Method
                Module        : System.Private.CoreLib.dll
            StackTrace :
   at System.RuntimeTypeHandle.MakeArray(Int32 rank)
   at System.RuntimeType.MakeArrayType(Int32 rank)
   at System.Management.Automation.Language.ArrayTypeName.GetReflectionType()
   at System.Management.Automation.Language.SymbolResolver.VisitArrayTypeName(ArrayTypeName arrayTypeName)
   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.StatementBlockAst.InternalVisit(AstVisitor visitor, ReadOnlyCollection`1 traps, ReadOnlyCollection`1
statements, AstVisitAction action)
   at System.Management.Automation.Language.NamedBlockAst.InternalVisit(AstVisitor visitor)
   at System.Management.Automation.Language.ScriptBlockAst.InternalVisit(AstVisitor visitor)
   at System.Management.Automation.Language.Ast.Visit(AstVisitor astVisitor)
   at System.Management.Automation.Language.SymbolResolver.ResolveSymbols(Parser parser, ScriptBlockAst scriptBlockAst)
   at System.Management.Automation.Language.ScriptBlockAst.PerformPostParseChecks(Parser parser)
   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)
            Source     : System.Private.CoreLib
            HResult    : -2146233054
        Source         : System.Management.Automation
        HResult        : -2146233087
    Source         : System.Management.Automation
    HResult        : -2146233087
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : ParseException
InvocationInfo        :
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : -1
    Line             : $a = [System.Management.Automation.Language.Parser]::ParseInput('[int[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]]', [ref]$null,
[ref]$null)
    PositionMessage  : At line:1 char:1
                       + $a = [System.Management.Automation.Language.Parser]::ParseInput('[int …
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

PS:3> $PSVersionTable

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

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions