php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38092 Upload of Image damages the image
Submitted: 2006-07-13 11:03 UTC Modified: 2006-07-30 01:00 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: rene dot schernus at siemens dot com Assigned:
Status: No Feedback Package: Apache2 related
PHP Version: 4.4.2 OS: RedHat ES30
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: rene dot schernus at siemens dot com
New email:
PHP Version: OS:

 

 [2006-07-13 11:03 UTC] rene dot schernus at siemens dot com
Description:
------------
If i upload an jpg-file and save the stream to disk my jpg is damaged after this. If i view the "source" of the jpg i can see that the html-form data is appended. "Content-Disposition: form-data; name="userpic"; filename="66_automotive_102x72_1305008.jpg" Content-Type: image/jpeg". The size of the file i doubled.
If i set an directive in the apache config like 
"ForceType image/jpg" and upload again the jpg isn?t damaged.



Reproduce code:
---------------
Upload Source:
<?php
$original       = $_FILES['userpic']['tmp_name'];
$filename                               = $_FILES['userpic']['name'];

if ($original != '') {
        copy($_FILES["userpic"]["tmp_name"], "./tmp/".$filename);
        $filename= "./tmp/".$filename;
        print "<img src=".$filename.">";
        $handle = fopen ($original, "rb");
        $contents = fread ($handle, filesize ($original));
        $len = strlen($contents);
        $pos = strpos($contents, 'Type:');
        #print "<BR>";
        #print "<BR>";

        print $contents."<BR>";
        fclose ($handle);
        exit;
}
?>
<FORM enctype="multipart/form-data" method="post">
<TABLE>
<TR><TD>&nbsp;
<INPUT type='file' name='userpic' /><input name='weilhalt' type='hidden' value='wert'><INPUT type='hidden' name='target_input' value="seite_teaser" /></TD>
<TD align='right'><INPUT type='submit' name='confirm' class='button' value='hochladen' /><BR></TD></TR>
</TABLE>
        </form>


Expected result:
----------------
A normal upload.





Actual result:
--------------
Source of uploaded jpg:

--snip--

^@^@^@H^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@8BIM^D^Q^@^@^@^@^@^A^A^@8BIM^D^T^@^@^@^@^@-----------------------------7301164174495^M
Content-Disposition: form-data; name="userpic"; filename="66_automotive_102x72_1305008.jpg"^M
Content-Type: image/jpeg^M
^M
ÿ?ÿ? ^@^PJFIF^@^A^B^A^@·^@·^@^@ÿí^N¦Photoshop 3.0^@8BIM^Cí^@^@^@^@^@^P^@¶áH^@^B^@^B^@¶áH^@^B^@^B8BIM^D^M^@^@^@^@IM^D^Y^@^@^@^@^@^D^@^@^@^^8BIM^Có^@^@^@^@^@ ^@^@^@^@^@^@^@^@^A^@8BIM^D
^@^@^@^@^@^A^@^@8BIM'^P^@^@^@^@^@

--snip--

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-13 11:18 UTC] tony2001@php.net
Which web-server is that? Which PHP SAPI is used? Did you try it on a different host/OS/webserver?
Definitely not reproducible here.
 [2006-07-13 12:46 UTC] rene dot schernus at siemens dot com
Apache Webserver 2.0.46, Server API Apache 2.0 Filter.

Yes i tried on a different host. Redhat ES40, Apache 2.0.55, Server API 	Apache 2.0 Handler and it works fine.

thx
 [2006-07-13 12:54 UTC] tony2001@php.net
Please update Apache to the latest available 2.0.x version and see if it helps.
 [2006-07-17 12:00 UTC] rene dot schernus at siemens dot com
Hi,

the cause is the SAPI. If i user the "Apache2Filter" my problem is still there. It doesn?t matter what Apache version  or OS i have.
If i user the "Apache2Handler" everything works fine.

./configure -apxs2=/usr/sbin/apxs'   (Use of Apache2Handler)
./configure --with-apxs2filter=/usr/sbin/apxs (Use of Apache2Filter)

thx for your help. your question about the used sapi opend my eyes.
 [2006-07-22 12:15 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2006-07-30 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 28 04:01:28 2024 UTC