ZF-8791: Error: Pdf file syntax error. 'startxref' keyword expected. Offset - 0x2180.

Issue Type: Bug Created: 2010-01-12T12:21:54.000+0000 Last Updated: 2010-05-27T12:43:06.000+0000 Status: Resolved Fix version(s): - 1.10.6 (22/Jun/10)

Reporter: Gerrit Kamp (gkamp) Assignee: Pádraic Brady (padraic) Tags: - Zend_Pdf

Related issues: Attachments: - Zend_Pdf_StringParser.patch


Zend_Pdf_Parser gives an error on line 440: $this->_stringParser->readLexeme();

The parser works fine on my local Windows XP development machine, but it crashes on my Ubuntu 8.04 Linux server. The code is exactly identical on both machines, and so is the PDF file that I am loading with Zend_Pdf::load().

The error stack is below:

Error: Pdf file syntax error. 'startxref' keyword expected. Offset - 0x2180.

0 /home/mvm_stevens/www_mvm/library/Zend/Pdf.php(303): Zend_Pdf_Parser->__construct('/home/mvm_steve...', Object(Zend_Pdf_ElementFactory_Proxy), true)

1 /home/mvm_stevens/www_mvm/library/Zend/Pdf.php(253): Zend_Pdf->__construct('/home/mvm_steve...', NULL, true)

2 /home/mvm_stevens/www_mvm/application/models/Report/Pdf.php(15): Zend_Pdf::load('/home/mvm_steve...')

3 /home/mvm_stevens/www_mvm/application/controllers/ReportsController.php(102): Report_Pdf->loadTemplate('10_slf_mon1_tem...')

4 /home/mvm_stevens/www_mvm/application/controllers/ReportsController.php(38): ReportsController->createReport(Array)

5 /home/mvm_stevens/www_mvm/library/Zend/Controller/Action.php(513): ReportsController->initialrepAction()

6 /home/mvm_stevens/www_mvm/library/Zend/Controller/Dispatcher/Standard.php(289): Zend_Controller_Action->dispatch('initialrepActio...')

7 /home/mvm_stevens/www_mvm/library/Zend/Controller/Front.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))

8 /home/mvm_stevens/www_mvm/application/bootstrap.php(56): Zend_Controller_Front->dispatch()

9 /home/mvm_stevens/www_mvm/index.php(11): Bootstrap->runApp()

10 {main}

I outcommented the lines 440 until 453 in Parser.php and echoed the content of $data to the browser, to see if the PDF file is properly read with the 'fread' function, and the output almost identical. The Ubuntu machine seems to recognize more characters. For example, the Windows version showed the following as the 2nd line: %���� and Ubuntu showed: %âãÏÓ

Anybody any ideas what is going on or what I can do to get the Ubuntu server load these PDF files?


Posted by Kai Bielenberg (kaib) on 2010-01-15T02:52:38.000+0000

I had the same issue. The problem in my case was that i configure mbstring.func_overload to use mbstring functions instead of the normal string functions. Try something like this to see if this is also your problem:

ini_set('mbstring.internal_encoding', 'ASCII'); $pdf = Zend_Pdf::load('my.pdf'); ini_set('mbstring.internal_encoding', 'UTF-8');

Posted by Michael Kofler (miko) on 2010-02-16T06:33:14.000+0000

mbstring setting didn't help for me

PDF handling worked flawless both with zf 1.5.1 (ubuntu 8.04) and zf 1.9.4 (ubuntu 9.10);

zend 10.1 on ubuntu 8.04 did not work (error as described above), so I went back to 1.5.1 on this machine

Posted by Nicolas CORMIER (nicolascormier) on 2010-02-17T17:07:38.000+0000

Exact same issue as Michael...

Ubuntu 8.04.3 and Zend 10.1

Posted by Yaroslav Golovach (yaroslav.golovach) on 2010-02-19T08:45:32.000+0000

I've encountered the same problem on one domain hosting based on linux. I tried zf 1.5.1 and some versions between 1.5.1 and 10.1 but nothing helped. Zf 1.5.1 displayed another problem than "'startxref' keyword expected" (I haven't written it down) but it also failed.

After some investigation I discovered that code at line 440 $this->_stringParser->readLexeme() is actually expected to read 'startxhref' word from pdf file. But in fact it reads 'startxhre' (without 'f' at the end) so exception is thrown.

Posted by Quintin Venter (quintinventer) on 2010-03-11T08:05:50.000+0000

We had a similar issue.

On my Windows machine running Zend 1.9.6 and Php 5.2.8 it all worked fine. We then rolled it out to our live systems where it only works on one of the two Ubuntu machines.

I was tasked with figuring out what is happening here. We found that our one system is runnin PHP 5.2.4 and the other is running 5.2.5 both with Zend 1.9.6.

The one running 5.2.5 is working fine but the one with 5.2.4 is giving us the problems.

I then had a look at the StringParser.php. In there you will find that Zend 1.9.6 checks for \f as one of the white space characters. This is not supported in version 5.2.4 yet ( So I had to go do a version check and adjust the data parser.

You want to go to line 267 and replace it with the following block of code:

$compare = ""; if ( version_compare( phpversion(), '5.2.5' ) >= 0 ) { // this version added support for the escaped form feed character $compare = "()<>[]{}/%\x00\t\n\f\r "; } else { $compare = "()<>[]{}/%\x00\t\n\r "; }

$this->offset += strcspn($this->data, $compare, $this->offset);

Hope this solves your problem.

Posted by Yaroslav Golovach (yaroslav.golovach) on 2010-03-11T08:38:17.000+0000

Thanks a lot, Quintin.

Your fix works great :).

Posted by Christiaan Kras (htbaa) on 2010-03-31T02:12:58.000+0000

Could this be fixed and backported to 1.9.7 (1.9.8 perhaps?) as the minimum requirement for ZF is PHP 5.2.4 and not PHP 5.2.5.

Posted by Christiaan Kras (htbaa) on 2010-05-02T23:45:01.000+0000

This is a serious showstopper. Could this PLEASE be fixed ASAP so we don't have to patch StringParser.php ourselves? This fix is here, please apply it.

Posted by Christiaan Kras (htbaa) on 2010-05-02T23:53:50.000+0000

This patch applies to Zend_Pdf_StringParser of ZendFramework 1.10.4

Posted by Christiaan Kras (htbaa) on 2010-05-25T04:11:38.000+0000

I'm sorry for spamming this issue, but could this fix be applied before the next mini-release?

Posted by Pádraic Brady (padraic) on 2010-05-27T06:11:08.000+0000

Sorry for the delay guys, I'm not a Zend_Pdf maintainer but I noticed your Devzone comment ;). Ask, and thou shalt receive! So I reviewed the patch. Fix looks good so I've applied it in r22311. Worth noting, there are always devs around on our regular bug hunt days - if there are other patches anyone needs applying you can grab us on IRC at those times for assistance.

Will apply this to the release branch soon for next mini-release.

Posted by Christiaan Kras (htbaa) on 2010-05-27T06:48:45.000+0000

Thanks for resolving this, much appreciated.

Posted by Quintin Venter (quintinventer) on 2010-05-27T06:57:54.000+0000

Thanks a mil.

Posted by Michael Kliewe (mkliewe) on 2010-05-27T12:43:06.000+0000

Thank you for applying it, Padraic.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.