You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2023/09/18 16:48:54 UTC
svn commit: r1912400 - in /pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox: cos/COSObjectKey.java pdfparser/BaseParser.java
Author: lehmi
Date: Mon Sep 18 16:48:53 2023
New Revision: 1912400
URL: http://svn.apache.org/viewvc?rev=1912400&view=rev
Log:
PDFBOX-5682: don't use hashCode as key to avoid collisions
Modified:
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObjectKey.java
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
Modified: pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObjectKey.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObjectKey.java?rev=1912400&r1=1912399&r2=1912400&view=diff
==============================================================================
--- pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObjectKey.java (original)
+++ pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObjectKey.java Mon Sep 18 16:48:53 2023
@@ -87,6 +87,16 @@ public final class COSObjectKey implemen
}
/**
+ * Return the internal hash value which is based on the number and the generation.
+ *
+ * @return the internal hash value
+ */
+ public long getInternalHash()
+ {
+ return numberAndGeneration;
+ }
+
+ /**
* {@inheritDoc}
*/
@Override
Modified: pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java?rev=1912400&r1=1912399&r2=1912400&view=diff
==============================================================================
--- pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java (original)
+++ pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java Mon Sep 18 16:48:53 2023
@@ -57,7 +57,7 @@ public abstract class BaseParser
private final CharsetDecoder utf8Decoder = StandardCharsets.UTF_8.newDecoder();
- private final Map<Integer, COSObjectKey> keyCache = new HashMap<>();
+ private final Map<Long, COSObjectKey> keyCache = new HashMap<>();
/**
* Log instance.
@@ -166,11 +166,11 @@ public abstract class BaseParser
{
for (COSObjectKey key : xrefTable.keySet())
{
- keyCache.putIfAbsent(key.hashCode(), key);
+ keyCache.putIfAbsent(key.getInternalHash(), key);
}
}
- int hashCode = Long.hashCode(COSObjectKey.computeInternalHash(num, gen));
- COSObjectKey foundKey = keyCache.get(hashCode);
+ long internalHashCode = COSObjectKey.computeInternalHash(num, gen);
+ COSObjectKey foundKey = keyCache.get(internalHashCode);
return foundKey != null ? foundKey : new COSObjectKey(num, gen);
}