php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: vanherkmarcel at gmail dot com
New email:
PHP Version: OS:

 

 [2020-10-24 18:19 UTC] vanherkmarcel at gmail dot com
Description:
------------
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']));
  pclose($handle)

Expected result:
----------------
Data is transmitted as is without interference

Actual result:
--------------
0x0a replaced by 0x0a 0x0d

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-26 16:17 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-10-26 16:17 UTC] cmb@php.net
> 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
Hi,

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.

Marcel
 [2020-10-27 18:14 UTC] cmb@php.net
-Status: Assigned +Status: Verified
 [2020-10-27 18:14 UTC] cmb@php.net
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] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2020-10-27 22:44 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=101793286959d1113af940727b5c6e2101ac2303
Log: Fix #80282: cannot send binary data to popen
 [2020-10-27 22:44 UTC] phpdocbot@php.net
-Status: Verified +Status: Closed
 [2020-10-28 01:15 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=9b3cf9cb9871bf78c9ffc468f684642957d4003f
Log: Fix #80282: cannot send binary data to popen
 [2020-10-28 10:36 UTC] vanherkmarcel at gmail dot com
Thanks!
 [2020-12-30 11:58 UTC] nikic@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=bdc853684e048d03c19a24573ff9d516391e321f
Log: Fix #80282: cannot send binary data to popen
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 03 13:01:28 2024 UTC