PowerShell / PowerShell

PowerShell for every system!
https://microsoft.com/PowerShell
MIT License
43.55k stars 7.06k forks source link

Invoke-WebRequest cashes pwsh installed with latest brew and throws malloc error (PowerShell 7.4.2) #21602

Closed b3hni4 closed 5 days ago

b3hni4 commented 2 weeks ago

Prerequisites

Steps to reproduce

This only happens with POST requests to the same uri (GET request works as intended)

$serviceUsername = 'XXX'
$serviceUserPassword = Read-Host -AsSecureString
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $serviceUsername, $serviceUserPassword
$body = @{foo = "foo"}
$parameters = @{
          Uri         = "https://xxx.net"
          METHOD      = "POST"
          Credential  = $cred
          Body        = $body | ConvertTo-Json 
          ContentType = 'application/json'
      }
$response = Invoke-WebRequest @parameters
---

pwsh(66802,0x70000453e000) malloc: *** error for object 0x600002bdef20: pointer being freed was not allocated
pwsh(66802,0x70000453e000) malloc: *** set a breakpoint in malloc_error_break to debug
Abort trap: 6

This does not happen in version 7.3.12

Expected behavior

Web request returns as expected.

Actual behavior

Shell crashes.

Error details

Get-Error cannot be called as the shell crashes with the following error

pwsh(66802,0x70000453e000) malloc: *** error for object 0x600002bdef20: pointer being freed was not allocated
pwsh(66802,0x70000453e000) malloc: *** set a breakpoint in malloc_error_break to debug
Abort trap: 6

### Environment data

```powershell
Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Darwin 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:11:05 PDT 2024; root:xnu-10063.101.17~1/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

SteveL-MSFT commented 1 week ago

Need more specific steps that repro to be able to debug this. The malloc should be happening within .NET runtime and not within the cmdlet. A simple scenario like invoke-webrequest -uri 'https://httpbin.org/post' -Method Post -Body @{foo='bar'} works.

microsoft-github-policy-service[bot] commented 5 days ago

This issue has been marked as "Waiting on Author" and has not had any activity for 7 day. It has been closed for housekeeping purposes.

microsoft-github-policy-service[bot] commented 5 days ago

📣 Hey @b3hni4, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

Microsoft Forms