[php-src] Issue #9456: finfo_file returns wrong mime type for some pdf files
| From: | Darhakexge | Date: | Wed, 31 Aug 2022 15:10:50 +0000 |
| Subject: | [php-src] Issue #9456: finfo_file returns wrong mime type for some pdf files | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242347@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9456
Author: Darhakexge
### Description
finfo_file returns incorrect mime type on pdf files that have leading spaces in the
first line.
The following code:
```php
<?php
$finfo = new \finfo(\FILEINFO_MIME_TYPE));
$mimeType = $finfo->file($path);
echo $mimeType;
```
Resulted in this output:
```
"application/octet-stream"
```
But I expected this output instead:
```
expected result is: "application/pdf"
```
While debugging I found that if the file has leading spaces in the first line
finfo_file can't get the mimetype correctly. Removing the spaces manually allows
finfo_file get the mime type as expected
```diff
- %PDF-1.7 <-- Notice the space at the beginning
+%PDF-1.7
1 0 obj
<< /Type /Catalog
/Outlines 2 0 R
/Pages 3 0 R >>
endobj
...
```
### PHP Version
8.1.9
### Operating System
Ubuntu 18.04, Ubuntu 20.04, Windows 10, Windows 11