Hello again, I created two alternative patches for this issue, since the first one feels rather ugly. With patch v2, I switched the PdfReference parameter to call-by-value instead of call-by-reference. With patch v3, I kept the parameter as it is, but passed a local copy of the required PdfReference to the function.
With either of the three patches, the annotations are deleted without leftover objects, as it should be. Greetings, F.E. Am Mo., 1. Apr. 2019 um 11:47 Uhr schrieb F. E. <exler7...@gmail.com>: > Hello again, > > I created a simple patch for this issue. The ref parameter is copied into > a local refCpy variable, which is later used instead of the invalidated ref > parameter for deleting the annotation and pdf object. Tested the patch > against a sample pdf, the annotations are now correctly removed, nothing is > left behind. > > Greetings, > F.E. > > Am Fr., 29. März 2019 um 13:30 Uhr schrieb F. E. <exler7...@gmail.com>: > >> Hello dear podofo users, >> >> I stumbled upon an issue with the deletion of annotations today: >> >> PdfPage.cpp:409ff >> >>> void PdfPage::DeleteAnnotation( int index ) >>> { >>> PdfObject* pObj = this->GetAnnotationsArray( false ); >>> PdfObject* pItem; >>> [..] >>> pItem = &(pObj->GetArray()[index]); >>> if( pItem->IsDictionary() ) >>> { >>> [..] >>> } >>> else >>> { >>> this->DeleteAnnotation( pItem->GetReference() ); >>> } >>> } >>> >> >> When calling DeleteAnnotation with an index, the requested Annotation is >> stored into pItem. In my case it is not a dictionary, so DeleteAnnotation >> with a Reference is called: >> >> PdfPage.cpp:446ff >> >>> void PdfPage::DeleteAnnotation( const PdfReference & ref ) >>> { >>> [..] >>> >> while( it != pObj->GetArray().end() ) >>> { >>> if( (*it).IsReference() && (*it).GetReference() == ref ) >>> { >>> pObj->GetArray().erase( it ); >>> bFound = true; >>> break; >>> } >>> ++it; >>> } >>> [..] >>> delete this->GetObject()->GetOwner()->RemoveObject( ref ); >>> } >>> >> >> Here, the reference is removed from the array and the corresponding >> object is deleted at the end. >> *The problem is, the erase operation on the array destroys the reference >> ref! *I can see with the debugger that Ref's object number changes after >> the erase, so the subsequent RemoveObject call is in error! It either tries >> to remove a non-existing object (best-case) or some other unrelated object >> (worst-case), depending on what values are stored at the location now. >> When checking the resulting PDF, I can see that the annotation objects >> are still there, but it was removed from the page's annotation list. >> >> I guess the fix might be quite easy: >> Either pass the PdfReference by value instead of by reference, or copy it >> into a local before removing it from the array, so a valid PdfReference >> object can be used for subsequent removal. >> I didn't have time to test this myself today, though. >> >> Could someone confirm my findings, please? >> Greetings >> F.E. >> >> p.s.: Sorry for the first, uncomplete mail, didn't know gmail sends the >> mail right away when pressing CTRL+Enter >> >
pdfpage_delete_annotation_fix_3.patch
Description: Binary data
pdfpage_delete_annotation_fix_2.patch
Description: Binary data
_______________________________________________ Podofo-users mailing list Podofo-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/podofo-users