On 23 February 2018 at 01:32, Matthew Brincke <ma...@mailbox.org> wrote: > you mean that the GetKey() call in > src/doc/PdfPagesTree.cpp line 620 throws then?
No. The crash I noticed will happen with empty document, calling InserPage with index 0. PdfPagesTreeCache::AddPageObject() will be called with -1, crashing on "m_deqPageObjs[-1] = pPage;" > I didn't/don't want to change this API (including the special meaning of > the index -1) I don't want to change the API either. Currently the index will be clamped, sort of, at the following lines: if (atIndex < 0 || atIndex >= this->GetTotalNumberOfPages()) { atIndex = this->GetTotalNumberOfPages() - 1; } The mistake is not allowing index equals to pageCount. The attached patch fixes this and adjust the index clamping. I tested it with following code: // PageNumber is 1-based index assert(pageA->GetPageNumber() == 2); assert(pageB->GetPageNumber() == 1); assert(pageC->GetPageNumber() == 3); // Insert ouf of bounds auto page = document.InsertPage(rect, -1); assert(page->GetPageNumber() == 1); int pageCount = document.GetPageCount(); page = document.InsertPage(rect, pageCount + 1); assert(page->GetPageNumber() == pageCount + 1); // Insert in the middle page = document.InsertPage(rect, 2); assert(page->GetPageNumber() == 3);
Fix-crash-inserting-page-at-index-equals-to-page-count.patch
Description: Binary data
------------------------------------------------------------------------------ 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