php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36801 imagecreagefromstring accepts content of MPEG files
Submitted: 2006-03-20 19:08 UTC Modified: 2006-03-20 21:56 UTC
From: glavoie at mutehq dot net Assigned:
Status: Not a bug Package: GD related
PHP Version: 5.1.2 OS: Debian Sarge GNU/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: glavoie at mutehq dot net
New email:
PHP Version: OS:

 

 [2006-03-20 19:08 UTC] glavoie at mutehq dot net
Description:
------------
If I give the content of a MPEG file to imagecreatefromstring, it doesn't return an error. This is causing me an headach with HTTP graphic file upload since I must be sure that uploaded files are realli graphic ones for resizing.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-20 19:13 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2006-03-20 21:44 UTC] glavoie at mutehq dot net
I use this script to convert images to JPEG with resizing when needed. When a MPEG file is given to imagecreatefromstring(), $source doesn't return false and I get an images($source) of 1 and a imagesy($source) of ~7000. When creating the new resized image with imagecreatetruecolor, the ratio is huge and an image of about 2.5 GB is created in memory. 

<?php

if ( isset( $_GET['width'] ) )
        $width = $_GET['width'];
else
        $width = 0;

        $source = imagecreatefromstring( file_get_contents('1.mpg')  );

        if ($source)
        {
                if ( $width )
                {
                        $ratio = $width / imagesx( $source );

                        $resized = imagecreatetruecolor( $width, $ratio * imagesy( $source ) );

                        imagecopyresampled( $resized, $source, 0, 0, 0, 0, $width, $ratio * imagesy( $source ), imagesx( $source ), imagesy( $source ) );

                        $source = $resized;
                }

                ob_start();
                        imagejpeg($source);
                        $photo = ob_get_contents();
                ob_end_clean();

                header( 'Content-type: image/jpeg' );
                echo $photo;
        }
?>
 [2006-03-20 21:56 UTC] tony2001@php.net
Looks like you're using MPEG-JPEG codec and libgd detects your file as JPEG image. I'm not sure if anything can be done about it, but it's definitely not PHP problem.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 14 20:01:31 2024 UTC