|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80282 cannot send binary data to popen
Submitted: 2020-10-24 18:19 UTC Modified: 2020-10-28 10:36 UTC
From: vanherkmarcel at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Filesystem function related
PHP Version: 7.4.11 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
26 - 16 = ?
Subscribe to this entry?

 [2020-10-24 18:19 UTC] vanherkmarcel at gmail dot com
I am attempting to send binary data to a process openened with popen under windows. However, any 0x0a is appended with a 0x0d, and there is no option to turn this of: popen($exe, 'wb') fails.

Test script:
  $handle = popen($exe, 'w');
  fwrite($handle, file_get_contents($_FILES['filetoupload']['tmp_name']));

Expected result:
Data is transmitted as is without interference

Actual result:
0x0a replaced by 0x0a 0x0d


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-26 16:17 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-10-26 16:17 UTC]
> popen($exe, 'wb') fails

I cannot reproduce that.  What exactly fails?  Is there some error
message?  Which executable do you call?
 [2020-10-26 21:58 UTC] vanherkmarcel at gmail dot com
-Status: Feedback +Status: Assigned
 [2020-10-26 21:58 UTC] vanherkmarcel at gmail dot com

Thanks for trying.

I lost my test code, since I programmed around it. My exe is the CGI interface of a DICOM server (Conquest DICOM server), and I was using php to forward a POST request to is CGI client dgate.exe. By default popen($exe, "w") opens in text mode on Windows - this is not documented. popen($exe, "wb") is not documented either, and when I tried it did seem not start my exe. There may have been a mixup with PHP versions though.

 [2020-10-27 18:14 UTC]
-Status: Assigned +Status: Verified
 [2020-10-27 18:14 UTC]
Okay, thanks for the explanation.  popen() indeed defaults to text
mode on Windows, what explains the reported issue.  However, $mode
'wb' is supossed to enable binary mode, and it does so for me (it
is important to write that as 'wb', not as 'bw' or 'w b' etc.)
Since you can no longer reproduce the problem with 'wb', I'm
changing to documentation bug.  Please open a new ticket, if you
ever stumble upon 'wb' prepending 0x0D to any 0x0A bytes.
 [2020-10-27 18:14 UTC]
-Type: Bug +Type: Documentation Problem
 [2020-10-27 22:44 UTC]
Automatic comment on behalf of cmb
Log: Fix #80282: cannot send binary data to popen
 [2020-10-27 22:44 UTC]
-Status: Verified +Status: Closed
 [2020-10-28 01:15 UTC]
Automatic comment on behalf of mumumu
Log: Fix #80282: cannot send binary data to popen
 [2020-10-28 10:36 UTC] vanherkmarcel at gmail dot com
 [2020-12-30 11:58 UTC]
Automatic comment on behalf of mumumu
Log: Fix #80282: cannot send binary data to popen
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Feb 08 05:05:48 2023 UTC