FAQ
Edit report at https://pear.php.net/bugs/bug.php?id=17703&edit=1

ID: 17703
Comment by: pear@kingsquare.nl
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:

There are more valid mime types that can not pass this test. I found
that the only valid mime type for .svg files (image/svg+xml) doesn't
pass the test too...

I've changed the patch accordingly.


Previous Comments:
------------------------------------------------------------------------

[2012-01-10 09:15:53] kingsquare

Added #patch bug:17703;patch:svgSupport;revision:1326186953;.

------------------------------------------------------------------------

[2011-11-17 16:13:33] schtorch

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

------------------------------------------------------------------------

[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.

------------------------------------------------------------------------

Search Discussions

  • Jens at Jan 10, 2012 at 10:27 am
    Edit report at https://pear.php.net/bugs/bug.php?id=17703&edit=1

    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:

    Nice catch kingsquare.

    I found additional mime types that are now considered correct with your
    patch:
    epub files, application/epub+zip
    fb2 files, text/fb2+xml
    xhtml files, application/xhtml+xml


    Previous Comments:
    ------------------------------------------------------------------------

    [2012-01-10 09:16:07] kingsquare

    There are more valid mime types that can not pass this test. I found
    that the only valid mime type for .svg files (image/svg+xml) doesn't
    pass the test too...

    I've changed the patch accordingly.

    ------------------------------------------------------------------------

    [2012-01-10 09:15:53] kingsquare

    Added #patch bug:17703;patch:svgSupport;revision:1326186953;.

    ------------------------------------------------------------------------

    [2011-11-17 16:13:33] schtorch

    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

    ------------------------------------------------------------------------

    [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.

    ------------------------------------------------------------------------

    The remainder of the comments for this report are too long. To view
    the rest of the comments, please view the bug report online at
    http://pear.php.net/bugs/bug.php?id=17703
  • Daniel Oconnor at Jan 14, 2012 at 1:57 pm
    Edit report at https://pear.php.net/bugs/bug.php?id=17703&edit=1

    ID: 17703
    Updated by: daniel.oconnor@gmail.com
    Reported By: jens at bierkandt dot org
    Summary: MimeType validated incorrectly
    -Status: Analyzed
    +Status: Closed
    Type: Bug
    Package: HTTP_Download
    Operating System: OpenSuSE 11.0
    Package Version: 1.1.3
    PHP Version: Irrelevant
    -Assigned To:
    +Assigned To: doconnor
    Roadmap Versions:
    New Comment:

    -Status: Analyzed
    +Status: Closed
    -Assigned To:
    +Assigned To: doconnor
    This bug has been fixed in SVN.

    If this was a documentation problem, the fix will appear on pear.php.net
    by the end of next Sunday (CET).

    If this was a problem with the pear.php.net website, the change should
    be live shortly.

    Otherwise, the fix will appear in the package's next release.

    Thank you for the report and for helping us make PEAR better.




    Previous Comments:
    ------------------------------------------------------------------------

    [2012-01-10 11:28:16] schtorch

    Nice catch kingsquare.

    I found additional mime types that are now considered correct with your
    patch:
    epub files, application/epub+zip
    fb2 files, text/fb2+xml
    xhtml files, application/xhtml+xml

    ------------------------------------------------------------------------

    [2012-01-10 09:16:07] kingsquare

    There are more valid mime types that can not pass this test. I found
    that the only valid mime type for .svg files (image/svg+xml) doesn't
    pass the test too...

    I've changed the patch accordingly.

    ------------------------------------------------------------------------

    [2012-01-10 09:15:53] kingsquare

    Added #patch bug:17703;patch:svgSupport;revision:1326186953;.

    ------------------------------------------------------------------------

    [2011-11-17 16:13:33] schtorch

    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

    ------------------------------------------------------------------------

    [2010-08-15 04:34:49] doconnor

    -Status: Open
    +Status: Analyzed
    Thanks for the patch Jens

    ------------------------------------------------------------------------

    The remainder of the comments for this report are too long. To view
    the rest of the comments, please view the bug report online at
    http://pear.php.net/bugs/bug.php?id=17703

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedJan 10, '12 at 8:15a
activeJan 14, '12 at 1:57p
posts3
users2
websitepear.php.net

2 users in discussion

Jens: 2 posts Daniel Oconnor: 1 post

People

Translate

site design / logo © 2022 Grokbase