Dear PoDoFo team, PDF file with the wrong offset value in startxref are not read correctly. This is caused by searching the "xref" token after calling ReadXRef.The reason is that the resulting offset puts the parser after the "startxref" and the offset value tokens, causing search for the "xref" token to point to the "xref" part of the "startxref" token.
One of the possible ways to address the issue is in the attached patch file. Regards Nikita Shlyapnikov.
Index: PdfParser.cpp =================================================================== --- PdfParser.cpp (revision 1818) +++ PdfParser.cpp (working copy) @@ -620,24 +620,30 @@ } } -void PdfParser::ReadXRef( pdf_long* pXRefOffset ) +void PdfParser::FindXRef() { - FindToken( "startxref", PDF_XREF_BUF ); + FindToken("startxref", PDF_XREF_BUF); - if( !this->IsNextToken( "startxref" ) ) + if (!this->IsNextToken("startxref")) { - // Could be non-standard startref - if(!m_bStrictParsing) { - FindToken( "startref", PDF_XREF_BUF ); - if( !this->IsNextToken( "startref" ) ) - { - PODOFO_RAISE_ERROR( ePdfError_NoXRef ); - } - } else - { - PODOFO_RAISE_ERROR( ePdfError_NoXRef ); - } + // Could be non-standard startref + if (!m_bStrictParsing) { + FindToken("startref", PDF_XREF_BUF); + if (!this->IsNextToken("startref")) + { + PODOFO_RAISE_ERROR(ePdfError_NoXRef); + } + } + else + { + PODOFO_RAISE_ERROR(ePdfError_NoXRef); + } } +} + +void PdfParser::ReadXRef( pdf_long* pXRefOffset ) +{ + FindXRef(); *pXRefOffset = this->GetNextNumber(); } Index: PdfParser.h =================================================================== --- PdfParser.h (revision 1818) +++ PdfParser.h (working copy) @@ -448,6 +448,10 @@ void ReadTrailer(); /** Looks for a startxref entry at the current file position + */ + void FindXRef(); + + /** Looks for a startxref entry at the current file position * and saves its byteoffset to pXRefOffset. * \param pXRefOffset store the byte offset of the xref section into this variable. */
------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________ Podofo-users mailing list Podofo-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/podofo-users