php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75625 Wrong Mime-Type returned by mime_content_type function with some PDF
Submitted: 2017-12-04 17:23 UTC Modified: 2017-12-04 17:58 UTC
From: vanderelst dot david at gmail dot com Assigned:
Status: Feedback Package: Filesystem function related
PHP Version: 7.0.26 OS: Debian 4.9.18-1
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-12-04 17:23 UTC] vanderelst dot david at gmail dot com
Description:
------------
When checking PDF, in some case the mime type returned by this function will be wrong.
The thing is that some editors add stuff before the %PDF string in the file.
And this is exactly the issue. The %PDF string can be found in the first 1024 bytes andkeep the PDF valid.

I tried to remove the specials chars from the file and the function detect the correct mime type.



Test script:
---------------
- Create a PDF
- test the function
- it swill return application/pdf
- edit the file and add some chars at the beginning before %PDF 
- retry and it will return text/plain



Expected result:
----------------
application/pdf

Actual result:
--------------
it returns text/plain 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-04 17:58 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2017-12-04 17:58 UTC] requinix@php.net
According to the official standard for application/pdf,
> All PDF files start with the characters "%PDF-"
> followed by the PDF version number, e.g., "%PDF-1.7" or
> "%PDF-2.0".  These characters are in US-ASCII encoding.
https://tools.ietf.org/html/rfc8118

If something inserted characters before the %PDF then it is not obeying the standard.

What characters and editors?
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC