php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23360 passthru probably modifies data
Submitted: 2003-04-26 06:13 UTC Modified: 2003-04-27 08:51 UTC
From: gerlach-rainer at gmx dot de Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.3.1 OS: FreeBSD 4.7-RC
Private report: No CVE-ID: None
 [2003-04-26 06:13 UTC] gerlach-rainer at gmx dot de
I write a little application that converts u-law
sound files on the fly to wave and sends the out-
put to the browser (IE6 on Windows XP). I use
mod_php4 on Apache/1.3.12 (Unix).


example script (lines splitted at _ for better readability):

<?PHP
if (isset($_GET['call'])) {
   header("Content-type: audio/x-wav");
   passthru( _
	"cat /var/isdn/" . $_GET['call'] . " | _
	/usr/sbin/g711conv -a | _
	/usr/local/bin/sox -t ul - -t wav -");
}
?>

The file is played, but at the end the voice output is choppy 
and the media player reports an "unsupported format" error.
I have tested the command line on the remote machine and get a 
file that is correctly played by media player.

I downloaded the file with IE 6 and compared it with the original 
file, created on the remote machine. They have exact the length and
almost the same content, but have little differences at the beginning. 
Here is the beginning of each file:

orig:
00000000  5249 4646 2478 0100 5741 5645 666d 7420 RIFF$x..WAVEfmt
00000010  1000 0000 0700 0100 401f 0000 401f 0000 ........@...@...
00000020  0100 0800 6461 7461 0078 0100 f1fd 79f7 ....data.x..q}yw

after passthru:
00000000  5249 4646 ffff ff7f 5741 5645 666d 7420 RIFF....WAVEfmt
00000010  1000 0000 0700 0100 401f 0000 401f 0000 ........@...@...
00000020  0100 0800 6461 7461 dbff ff7f f1fd 79f7 ....data[...q}yw

I also tested to download the file with 
- wget from cygwin -> wrong
- wget from the same machine as the webserver -> wrong

this works:
<?PHP
if (isset($_GET['call'])) {
   header("Content-type: audio/x-wav");
   exec(_
	"cat /var/isdn/" . $_GET['call'] . " | _
	/usr/sbin/g711conv -a | _
	/usr/local/bin/sox -t ul - -t wav /tmp/call.wav");
   $fd=fopen ("/tmp/call.wav", "r");
   fpassthru($fd);
}
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-26 06:24 UTC] gerlach-rainer at gmx dot de
I write a little application that converts u-law
sound files on the fly to wave and sends the out-
put to the browser (IE6 on Windows XP). I use
mod_php4 on Apache/1.3.12 (Unix).

example script (lines splitted at _ for better readability):

<?PHP
if (isset($_GET['call'])) {
   header("Content-type: audio/x-wav");
   passthru( _
	"cat /var/isdn/" . $_GET['call'] . " | _
	/usr/sbin/g711conv -a | _
	/usr/local/bin/sox -t ul - -t wav -");
}
?>

The file is played, but at the end the voice output is choppy 
and the media player reports an "unsupported format" error.
I have tested the command line on the remote machine and get a 
file that is correctly played by media player.

I saved the link target and compared the result with the original 
file, created on the remote machine. They have exact the same length and
almost the same content, but have little differences at the beginning. 
Here is the beginning of each file:

orig:
00000000  5249 4646 2478 0100 5741 5645 666d 7420 RIFF$x..WAVEfmt
00000010  1000 0000 0700 0100 401f 0000 401f 0000 ........@...@...
00000020  0100 0800 6461 7461 0078 0100 f1fd 79f7 ....data.x..q}yw

after passthru:
00000000  5249 4646 ffff ff7f 5741 5645 666d 7420 RIFF....WAVEfmt
00000010  1000 0000 0700 0100 401f 0000 401f 0000 ........@...@...
00000020  0100 0800 6461 7461 dbff ff7f f1fd 79f7 ....data[...q}yw

I also tested to download the file with 
- wget from cygwin -> wrong
- wget from the same machine as the webserver -> wrong

this works:
<?PHP
if (isset($_GET['call'])) {
   header("Content-type: audio/x-wav");
   exec(_
	"cat /var/isdn/" . $_GET['call'] . " | _
	/usr/sbin/g711conv -a | _
	/usr/local/bin/sox -t ul - -t wav /tmp/call.wav");
   $fd=fopen ("/tmp/call.wav", "r");
   fpassthru($fd);
}
?>
 [2003-04-26 14:05 UTC] pollita@php.net
It may be the webserver doing the data manipulation, try explicitly setting the content encoding:

header('Content-encoding: 8bit');
header('Content-transfer-encoding: 8bit');

 [2003-04-27 08:27 UTC] gerlach-rainer at gmx dot de
I have tried the two suggested header lines
and found that it wasn't the cause.

But I discovered, that the modified Bytes contain
size information which is ex post written 
into the file. So I tried another version of
the command on the console:

cat /var/isdn/030425211148-660994-4105660994-7 | _
	/usr/sbin/g711conv -a | _
	/usr/local/bin/sox -t ul - -t .wav - | _
	cat > test.wav

and got the response:
/usr/local/bin/sox: Length in output .wav header 
will wrong since can't seek to fix it. 

Thats also the reason, why it works first creating 
the file and then sending the data with fpassthru().

So it is no php bug. Sorry for molesting you.
 [2003-04-27 08:51 UTC] derick@php.net
Not a PHP bug, so we mark it bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 06 10:01:31 2024 UTC