|  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
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:

Actual result:
it returns text/plain 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-04 17:58 UTC]
-Status: Open +Status: Feedback
 [2017-12-04 17:58 UTC]
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.

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

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