Hi Nenad,
could *you* please apply my patch which I have posted in an answer to your first post about this issue? The reason it wasn't accepted yet is probably lack of committer time for PoDoFo (or this issue), IMHO. The posted patch should solve the problem fine and avoid any changes to the definition of what parameters can be validly passed to the (private) method GetPageNode(), as changed by an earlier patch of mine accepted by a committer. I take decisions of people who I know to be committers as binding for the project. So any changes to the preconditions of GetPageNode() are now part of the project, and I therefore now wait for the review of my newer patch (to InsertPage() and InsertPages() in PdfPagesTree.cpp) by a committer. I have just re-checked that it AFAIK isn't in need of revision. I'm sorry for not having noticed that the (new?) preconditions are being violated before. AFAIK that isn't a reason to "revise" a patch which is already committed by someone who has more privileges with the project than I have, because the revision (relative to current trunk, of course) would just consist of the patch I posted in this thread (even though it isn't displayed as one discussion thread in the archive). So please accept and apply it as such. My reasoning for current preconditions of GetPageNode() can be read in the post of mine to which I attached that patch, so I won't repeat it here. Best regards, mabri ________________________________ From: Nenad Novak <nenad.no...@gmail.com> To: Matthew Brincke <mabr...@ymail.com>; podofo-users@lists.sourceforge.net Sent: 14:39 Friday, 9 October 2015 Subject: Re: [Podofo-users] unreachable-code and robustness fixes in PdfPagesTree::GetPageNode() Please, can you revise your patch again? What is happening during first page creation is that InsertPage(-1,pPage) is called with special page number ePdfPageInsertionPoint_InsertBeforeFirstPage, and InsertPage() is accepting this value as special case, see code. Anyway, a few lines later, a GetPageNode(0, ...) is called, and critical message is logged. So, it should be regular to call GetPageNode() with page number zero, which does not have any kids yet. At least you could not emit a diagnostic message, for a nPageNUM == 0 and numKids == 0. enumEPdfPageInsertionPoint{ ePdfPageInsertionPoint_InsertBeforeFirstPage = -1, ... }; PdfPagesTree.cpp:231 InsertPage( this->GetTotalNumberOfPages() - 1, pPage ); void PdfPagesTree::InsertPage( int nAfterPageIndex, PdfObject* pPage ) { bool bInsertBefore = false; !!! if( ePdfPageInsertionPoint_InsertBeforeFirstPage == nAfterPageIndex ) { bInsertBefore = true; !!! nAfterPageIndex = 0; } else if( nAfterPageIndex < 0 ) { ... return; } PdfObjectList lstParents; *** PdfObject* pPageBefore = this->GetPageNode( nAfterPageIndex, this->GetRoot(), lstParents ); Helloworld.cpp:120 pPage = document.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) ); PdfDocument.cpp:259 return m_pPagesTree->CreatePage( rSize ); PdfPagesTree.cpp:231 InsertPage( this->GetTotalNumberOfPages() - 1, pPage ); PdfPagesTree.cpp:120 this->InsertPage( nAfterPageIndex, inPage->GetObject() ); PdfPagesTree.cpp:144 PdfObject* pPageBefore = this->GetPageNode( nAfterPageIndex, this->GetRoot(), lstParents ); const size_t numDirectKids = rKidsArray.size(); const size_t numKids = GetChildCount(pParent); // use <= since nPageNum is 0-based if( static_cast<int>(numKids) <= nPageNum ) { PdfPagesTree.cpp:335 PdfError::LogMessage( eLogSeverity_Critical, "Cannot retrieve page %i from a document with only %i pages.", nPageNum, static_cast<int>(numKids) ); Starting program: D:\export\podofo\build\examples\helloworld\helloworld.exe a.pdf [New Thread 7156.0x1784] Breakpoint 1, Logger::LogMessage (this=0x6ec020 <logger>, eLogSeverity=PoDoFo::eLogSeverity_Critical, pszPrefix=0x689418 <CSWTCH.138+20> "CRITICAL: ", pszMsg=0x694090 <PoDoFo::PdfAnnotation::s_lNumActions+3192> "Cannot retrieve page %i from a document with only %i pages.", args=@0x22f87c: 0x22f898 "") at ..\..\..\examples\helloworld\helloworld.cpp:60 (gdb) where #0 Logger::LogMessage (this=0x6ec020 <logger>, eLogSeverity=PoDoFo::eLogSeverity_Critical, pszPrefix=0x689418 <CSWTCH.138+20> "CRITICAL: ", pszMsg=0x694090 <PoDoFo::PdfAnnotation::s_lNumActions+3192> "Cannot retrieve page %i from a document with only %i pages.", args=@0x22f87c: 0x22f898 "") at ..\..\..\examples\helloworld\helloworld.cpp:60 #1 0x00402be7 in PoDoFo::PdfError::LogMessageInternal (eLogSeverity=PoDoFo::eLogSeverity_Critical, pszMsg=0x694090 <PoDoFo::PdfAnnotation::s_lNumActions+3192> "Cannot retrieve page %i from a document with only %i pages.", args=@0x22f87c: 0x22f898 "") at ..\..\src\base\PdfError.cpp:551 #2 0x00402c8c in PoDoFo::PdfError::LogMessage (eLogSeverity=PoDoFo::eLogSeverity_Critical, pszMsg=0x694090 <PoDoFo::PdfAnnotation::s_lNumActions+3192> "Cannot retrieve page %i from a document with only %i pages.") at ..\..\src\base\PdfError.cpp:510 #3 0x00471d4c in PoDoFo::PdfPagesTree::GetPageNode (this=<optimized out>, nPageNum=<optimized out>, pParent=<optimized out>, rLstParents=...) at ..\..\src\doc\PdfPagesTree.cpp:335 #4 0x00473dbd in PoDoFo::PdfPagesTree::InsertPage (this=this@entry=0x34ac90, nAfterPageIndex=<optimized out>, pPage=<optimized out>) at ..\..\src\doc\PdfPagesTree.cpp:144 #5 0x004742b7 in InsertPage (inPage=<optimized out>, nAfterPageIndex=<optimized out>, this=<optimized out>) at ..\..\src\doc\PdfPagesTree.cpp:120 #6 PoDoFo::PdfPagesTree::CreatePage (this=<optimized out>, rSize=...) at ..\..\src\doc\PdfPagesTree.cpp:231 #7 0x0041dc2c in PoDoFo::PdfDocument::CreatePage (this=this@entry=0x22fb7c, rSize=...) at ..\..\src\doc\PdfDocument.cpp:259 #8 0x00401a4b in HelloWorld (pszFilename=<optimized out>) at ..\..\..\examples\helloworld\helloworld.cpp:120 #9 0x00677ca3 in main (argc=2, argv=0x342ec8) at ..\..\..\examples\helloworld\helloworld.cpp:261 (gdb) q PdfPagesTree::GetChildCount(002ec760) PdfPagesTree::GetIndirectKey(Count) pCount=002ecad0 PdfPagesTree::npages=0 PdfPagesTree::GetChildCount(002ec760) PdfPagesTree::GetIndirectKey(Count) pCount=002ecad0 PdfPagesTree::npages=0 CRITICAL: Cannot retrieve page 0 from a document with only 0 PdfPagesTree::GetChildCount(002ec760) PdfPagesTree::GetIndirectKey(Count) pCount=002ecad0 PdfPagesTree::npages=0 PdfPagesTree::GetChildCount(002ec760) PdfPagesTree::GetIndirectKey(Count) pCount=002ecad0 PdfPagesTree::npages=0 PdfPagesTree::GetChildCount(002ec760) PdfPagesTree::GetIndirectKey(Count) pCount=002edc70 PdfPagesTree::npages=1 ------------------------------------------------------------------------------ _______________________________________________ Podofo-users mailing list Podofo-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/podofo-users