Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word documents generated by PHPWord 0.14/0.16 are incompatible with "finfo" and "file" bytestream mimetype guessers #1753

Closed
vitanivanov opened this issue Nov 13, 2019 · 0 comments · Fixed by #2416

Comments

@vitanivanov
Copy link

The mimetype of Word2007 documents generated by PHPWord 0.14/0.16 cannot be determined correctly neither by Ubuntu 16.04 "file" command nor by PHP 7.2 finfo's bytestream mimetype guesser.

Ubuntu's file command and PHP 7.2's finfo command both read the files as binary and determine their mimetype based on logic, which parses the file's bytestream hexadecimal values.

When determining the mimetype of Word2007 documents generated by PHPWord 0.14/0.16, both executables fail to do so, hence returning "application/octet-stream".

In our application we rely on determining the mimetype, instead of trusting the meta info "Content-Type". Due to security reasons we don't allow uploading "application/octet-stream" which makes it impossible for us to upload files, generated by ourselves using PHPWord.

Steps to Reproduce

  1. Execute the following code, taken from PHPWord's documentation
<?php
require __DIR__ . '/vendor/autoload.php';

            $phpWord = new \PhpOffice\PhpWord\PhpWord();
            $section = $phpWord->addSection();
            $section->addText( '"Learn from yesterday, live for today, hope for tomorrow. '
                . 'The important thing is not to stop questioning." (Albert Einstein)');
            $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
            $objWriter->save('helloWorld.docx');
  1. Execute "file --mime-type -b {PATH_TO_FILE}"

Expected Behavior

"application/vnd.openxmlformats-officedocument.wordprocessingml.document" is returned

Current Behavior

"application/octet-stream" is returned

Context

  • PHP Version: 7.2
  • PHPWord Version: 0.14, 0.16
@vitanivanov vitanivanov changed the title The bytestream of word documents generated by PHPWord 0.14 cannot be determined The bytestream of word documents generated by PHPWord 0.14/0.16 is incompatible with bytestream mimetype guessers Nov 13, 2019
@vitanivanov vitanivanov changed the title The bytestream of word documents generated by PHPWord 0.14/0.16 is incompatible with bytestream mimetype guessers Word documents generated by PHPWord 0.14/0.16 are incompatible with "finfo" and "file" bytestream mimetype guessers Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

1 participant