[
https://issues.apache.org/jira/browse/PDFBOX-4540?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16836485#comment-16836485
]
Tilman Hausherr commented on PDFBOX-4540:
-----------------------------------------
OK, I thimk I'm closer to understand. The COSWriter as it is now does not
always keep the indirect references, only when incremental saving or when it is
a dictionary. So the code as it is now writes the numbers directly. Your new
code adds stuff to {{objectKeys}}, because that one is accessible. (Now you
know what I meant with "weird manipulations that were not thought about in the
first place" I mentioned in PDFBOX-4538). Thus new keys are created and you get
a "gap" and possibly worse.
Re collision, I don't think so. These are different objects. (These might be
identical objects when between -100 and 256, but that's not the case here. And
even if it was, I don't really see how there would be trouble)
So what you wish is that if a COSObject is already in {{objectKeys}}, then
there shouldn't be a new key assigned. Kindof makes sense. I'll sleep over this.
> COSWriter sometimes retrieves wrong ObjectKey
> ---------------------------------------------
>
> Key: PDFBOX-4540
> URL: https://issues.apache.org/jira/browse/PDFBOX-4540
> Project: PDFBox
> Issue Type: Bug
> Components: Writing
> Affects Versions: 2.0.14
> Reporter: Jonathan
> Priority: Major
> Labels: patch, pull-request-available
> Attachments: sample.pdf
>
>
> If a COSBase is directly embedded in a COSObject, it should not be assigned a
> new object number by the writer. We suggest the following implementation for
> `COSWriter.getObjectKey(COSBase)`:
> {code:java}
> /**
> * This will get the object key for the object.
> *
> * @param obj The object to get the key for.
> *
> * @return The object key for the object.
> */
> protected COSObjectKey getObjectKey( COSBase obj )
> {
> COSBase actual = obj;
> if( actual instanceof COSObject )
> {
> actual = ((COSObject)obj).getObject();
> }
> COSObjectKey key = null;
> key = objectKeys.get(obj);
> if( key == null && actual != null )
> {
> key = objectKeys.get(actual);
> }
> if (key == null)
> {
> setNumber(getNumber()+1);
> key = new COSObjectKey(getNumber(),0);
> objectKeys.put(obj, key);
> if( actual != null )
> {
> objectKeys.put(actual, key);
> }
> }
> return key;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]