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: 2018-05-05 21:50 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: vanderelst dot david at gmail dot com Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 7.0.26 OS: Debian 4.9.18-1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: vanderelst dot david at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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?
 [2018-05-05 21:50 UTC] requinix@php.net
-Status: Feedback +Status: No Feedback
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 10:01:29 2025 UTC