Skip to content
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

ScriptProperty extensions on String via Update-TypeData break ConvertTo-Json #7091

Open
rmbolger opened this issue Jun 17, 2018 · 2 comments

Comments

@rmbolger
Copy link

commented Jun 17, 2018

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-Json

Expected 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.0
@mklement0

This comment has been minimized.

Copy link
Contributor

commented Jun 17, 2018

Good find.

#5797 is essentially the same issue with respect to NoteProperty members (but without a crash) in that it also asks that such ETS properties be ignored during to-JSON serialization.

@msftrncs

This comment has been minimized.

Copy link
Contributor

commented 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.