ID: 17703
Comment by: jens@bierkandt.org
Reported By: jens at bierkandt dot org
Summary: MimeType validated incorrectly
Status: Analyzed
Type: Bug
Package: HTTP_Download
Operating System: OpenSuSE 11.0
Package Version: 1.1.3
PHP Version: Irrelevant
Roadmap Versions:
New Comment:
This error is still present in 1.1.5 .
The problem is, that the Mime Type "video/3gpp" (a video format commonly
used by mobiles) is valid, but rendered invalid when using
HTTP_Download. I can't set this mime type.
Here is a diff for 1.1.5 to fix it:
$ diff Download.php Download_old.php
600c600
< if (!preg_match('/^[a-z]+\w*\/[a-z]+[\w.;= -]*$/',
$content_type)) {
---
if (!preg_match('/^[a-z]+\w*\/[a-z0-9]+[\w.;= -]*$/',
$content_type)) {Best regards
Previous Comments:
------------------------------------------------------------------------
[2010-08-15 04:34:49] doconnor
-Status: Open
+Status: Analyzed
Thanks for the patch Jens
------------------------------------------------------------------------
[2010-08-14 20:00:10] schtorch
Update: video/3gpp does not work, video/mp4,audio/mp3 works without
patch.
------------------------------------------------------------------------
[2010-08-14 19:49:11] schtorch
Description:
------------
When defining a mime type in setContentType(), it is verified by
HTTP_Download, but incorrectly. If the mime type contains a number (e.g.
video/mp4,video/mp3), the script throws a Pear error.
Patch:
--- Download_old.php 2010-08-14 21:37:07.000000000 +0200
+++ Download.php 2010-08-14 21:37:50.000000000 +0200
@@ -554,7 +554,7 @@
*/
function setContentType($content_type =
'application/x-octetstream')
{
- if (!preg_match('/^[a-z]+\w*\/[a-z]+[\w.;= -]*$/',
$content_type)) {
+ if (!preg_match('/^[a-z]+\w*\/[a-z0-9]+[\w.;= -]*$/',
$content_type)) {
return PEAR::raiseError(
"Invalid content type '$content_type' supplied.",
HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE
Test script:
---------------
$dl = new HTTP_Download();
$dl->setFile($file);
$dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, basename($file));
$dl->setContentType('video/mp4');
$dl->send();
Expected result:
----------------
Correct mime type during download.
Actual result:
--------------
Mime type is not set.
------------------------------------------------------------------------