From 074c76a2cef8f60826454e07ff4c0ec4f4a2b186 Mon Sep 17 00:00:00 2001 From: PetSerAl Date: Sun, 26 Feb 2017 22:59:04 +0300 Subject: [PATCH 1/2] Add failing test --- test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 b/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 index f6476e3c023..04ebb0b9829 100644 --- a/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 +++ b/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 @@ -25,4 +25,9 @@ $ObjArray = [System.Management.Automation.LanguagePrimitives]::ConvertTo($col, [object[]]) $ObjArray.Length | Should Be $col.Count } + + It "Casting recursive array to bool should not cause crash" { + $a[0] = $a = [PSObject](,1) + [System.Management.Automation.LanguagePrimitives]::IsTrue($a) | Should Be $true + } } From 448e6d8851e8e4e87a2d223e909572f4e5ca35fc Mon Sep 17 00:00:00 2001 From: PetSerAl Date: Sun, 26 Feb 2017 23:02:12 +0300 Subject: [PATCH 2/2] Fixes #3207 --- src/System.Management.Automation/engine/LanguagePrimitives.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index eb44031531c..49f60511909 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -935,7 +935,7 @@ internal static bool IsTrue(IList objectArray) // but since we don't want this to recurse indefinitely // we explicitly check the case where it would recurse // and deal with it. - IList firstElement = objectArray[0] as IList; + IList firstElement = PSObject.Base(objectArray[0]) as IList; if (firstElement == null) {