Repository navigation
Closed
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-DuplicateThe issue is a duplicate.WG-Cmdletsgeneral cmdlet issues
Milestone
Description
Steps to reproduce
# add a ScriptProperty to System.String
Update-TypeData -TypeName System.String -MemberType ScriptProperty -MemberName Foo -Value { $this.ToUpper() }
# call ConvertTo-Json with an object that contains at least one string
'asdf' | ConvertTo-JsonExpected behavior
"asdf"
Actual behavior
Process is terminating due to StackOverflowException.
Aborted (core dumped)
In this simple example where the script value is $this.ToUpper(), crashing with a StackOverflowException happens reliably and relatively quickly. If the script value is changed to something more complex, the PowerShell process tends to hang and consume massive amounts of memory until it crashes or is terminated.
Environment data
This seems to affect both Windows PowerShell and PowerShell Core 6.0.2 regardless of OS platform. The tests I did were from Windows 10 1803 running Windows PowerShell 5.1 and PowerShell Core 6.0.2 both on Windows and Ubuntu 16.04 via WSL. I've included the $PSVersionTable output for all below.
# Win PowerShell 5.1
Name Value
---- -----
PSVersion 5.1.17134.112
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.112
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
# PowerShell Core 6.0.2 (Windows)
Name Value
---- -----
PSVersion 6.0.2
PSEdition Core
GitCommitId v6.0.2
OS Microsoft Windows 10.0.17134
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
# PowerShell Core 6.0.2 (Ubuntu 16.04)
Name Value
---- -----
PSVersion 6.0.2
PSEdition Core
GitCommitId v6.0.2
OS Linux 4.4.0-17134-Microsoft #112-Microsoft Thu Jun 07 22:57:00 PST 2018
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Reacted by Michael Klement
Metadata
Metadata
Assignees
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-DuplicateThe issue is a duplicate.WG-Cmdletsgeneral cmdlet issues
Activity
mklement0 commentedon Jun 17, 2018
Good find.
#5797 is essentially the same issue with respect to
NotePropertymembers (but without a crash) in that it also asks that such ETS properties be ignored during to-JSON serialization.msftrncs commentedon Mar 17, 2019
Still happening in 6.2 RC 1, and per #6847, the object might be converted to a hash first, something must be going wrong during that pre-conversion before being sent to NewtonSoft?
kganjam commentedon Oct 28, 2020
Still happening in 7.0.3. This bug caused me to lose more than a week dealing with an internal support team as I thought the issue was due to something wrong in their code. In fact, their code was simple calling ConvertTo-Json and I happened to have had some extension methods for System.String.
SteveL-MSFT commentedon Nov 4, 2020
Closing as dupe of #5797, carry on discussion in that one