[Git][java-team/libsambox-java][master] 3 commits: New upstream version 2.3.0

Markus Koschany (@apo) gitlab at salsa.debian.org
Sat Oct 2 00:18:33 BST 2021



Markus Koschany pushed to branch master at Debian Java Maintainers / libsambox-java


Commits:
785e2b27 by Markus Koschany at 2021-10-02T01:14:35+02:00
New upstream version 2.3.0
- - - - -
452c2296 by Markus Koschany at 2021-10-02T01:14:37+02:00
Update upstream source from tag 'upstream/2.3.0'

Update to upstream version '2.3.0'
with Debian dir 3a4249284e7f0907db954a2f0deeeaa2bf03d283
- - - - -
08476488 by Markus Koschany at 2021-10-02T01:15:17+02:00
Update changelog

- - - - -


22 changed files:

- debian/changelog
- pom.xml
- src/main/java/org/sejda/sambox/cos/COSBoolean.java
- src/main/java/org/sejda/sambox/cos/COSName.java
- src/main/java/org/sejda/sambox/cos/COSNull.java
- src/main/java/org/sejda/sambox/cos/COSNumber.java
- + src/main/java/org/sejda/sambox/cos/IndirectCOSObject.java
- src/main/java/org/sejda/sambox/cos/IndirectCOSObjectIdentifier.java
- src/main/java/org/sejda/sambox/input/BaseCOSParser.java
- src/main/java/org/sejda/sambox/input/ObjectsFullScanner.java
- src/main/java/org/sejda/sambox/input/XrefFullScanner.java
- src/main/java/org/sejda/sambox/input/XrefParser.java
- src/main/java/org/sejda/sambox/output/DefaultPDFWriter.java
- src/main/java/org/sejda/sambox/output/IndirectObjectsWriter.java
- src/main/java/org/sejda/sambox/output/IndirectReferencesAwareCOSWriter.java
- src/main/java/org/sejda/sambox/output/ObjectsStreamPDFBodyObjectsWriter.java
- src/main/java/org/sejda/sambox/output/PDFBodyWriter.java
- src/main/java/org/sejda/sambox/output/PDFWriteContext.java
- src/main/java/org/sejda/sambox/pdmodel/PDDocument.java
- src/main/java/org/sejda/sambox/pdmodel/graphics/color/PDColorSpace.java
- src/main/java/org/sejda/sambox/pdmodel/graphics/shading/PDShading.java
- src/main/java/org/sejda/sambox/xref/FileTrailer.java


Changes:

=====================================
debian/changelog
=====================================
@@ -1,3 +1,9 @@
+libsambox-java (2.3.0-1) unstable; urgency=medium
+
+  * New upstream version 2.3.0.
+
+ -- Markus Koschany <apo at debian.org>  Sat, 02 Oct 2021 01:15:04 +0200
+
 libsambox-java (2.2.19-1) unstable; urgency=medium
 
   * New upstream version 2.2.19.


=====================================
pom.xml
=====================================
@@ -5,7 +5,7 @@
 	<artifactId>sambox</artifactId>
 	<packaging>jar</packaging>
 	<name>sambox</name>
-	<version>2.2.19</version>
+	<version>2.3.0</version>
 
 	<description>An Apache PDFBox fork intended to be used as PDF processor for Sejda and PDFsam related projects</description>
 	<url>http://www.sejda.org</url>
@@ -33,7 +33,7 @@
 		<connection>scm:git:git at github.com:torakiki/sambox.git</connection>
 		<developerConnection>scm:git:git at github.com:torakiki/sambox.git</developerConnection>
 		<url>scm:git:git at github.com:torakiki/sambox.git</url>
-		<tag>v2.2.19</tag>
+		<tag>v2.3.0</tag>
 	</scm>
 
 	<developers>
@@ -52,17 +52,17 @@
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<maven.javadoc.failOnError>false</maven.javadoc.failOnError>
-		<bouncycastle.version>1.64</bouncycastle.version>
+		<bouncycastle.version>1.69</bouncycastle.version>
 		<fontbox.version>2.0.18</fontbox.version>
 		<sejda.commons.version>1.1.3</sejda.commons.version>
 		<sejda.io.version>2.1.1</sejda.io.version>
-		<slf4j.version>1.7.29</slf4j.version>
+		<slf4j.version>1.7.30</slf4j.version>
 	</properties>
 
 	<repositories>
 		<repository>
 			<id>pdfbox-snapshot</id>
-			<url>http://repository.apache.org/snapshots/</url>
+			<url>https://repository.apache.org/snapshots/</url>
 			<snapshots>
 				<enabled>true</enabled>
 			</snapshots>


=====================================
src/main/java/org/sejda/sambox/cos/COSBoolean.java
=====================================
@@ -64,4 +64,11 @@ public final class COSBoolean extends COSBase
     {
         visitor.visit(this);
     }
+
+    @Override
+    public void idIfAbsent(IndirectCOSObjectIdentifier id)
+    {
+        // we don't store id for booleans. We write them as direct objects. Wrap this with an IndirectCOSObject if you
+        // want to write a number as indirect reference
+    }
 }


=====================================
src/main/java/org/sejda/sambox/cos/COSName.java
=====================================
@@ -662,4 +662,11 @@ public final class COSName extends COSBase implements Comparable<COSName>
     {
         visitor.visit(this);
     }
+
+    @Override
+    public void idIfAbsent(IndirectCOSObjectIdentifier id)
+    {
+        // we don't store id for names. We write them as direct objects. Wrap this with an IndirectCOSObject if you
+        // want to write a number as indirect reference
+    }
 }


=====================================
src/main/java/org/sejda/sambox/cos/COSNull.java
=====================================
@@ -46,4 +46,11 @@ public final class COSNull extends COSBase
     {
         return "COSNull";
     }
+
+    @Override
+    public void idIfAbsent(IndirectCOSObjectIdentifier id)
+    {
+        // we don't store id for NULL. We write them as direct objects. Wrap this with an IndirectCOSObject if you
+        // want to write a number as indirect reference
+    }
 }


=====================================
src/main/java/org/sejda/sambox/cos/COSNumber.java
=====================================
@@ -88,4 +88,11 @@ public abstract class COSNumber extends COSBase
 
         return new COSFloat(number);
     }
+
+    @Override
+    public void idIfAbsent(IndirectCOSObjectIdentifier id)
+    {
+        // we don't store id for numbers. We write them as direct objects. Wrap this with an IndirectCOSObject if you
+        // want to write a number as indirect reference
+    }
 }


=====================================
src/main/java/org/sejda/sambox/cos/IndirectCOSObject.java
=====================================
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2021 Sober Lemur S.a.s. di Vacondio Andrea and Sejda BV
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.sejda.sambox.cos;
+
+import java.io.IOException;
+import java.util.Optional;
+
+/**
+ * A COSBase that will be written as indirect object. This can be used to wrap COSBase (COSName, COSInteger, COSNull,
+ * COSBoolean) that are otherwise written as direct object by the body writer.
+ * 
+ * @author Andrea Vacondio
+ */
+public class IndirectCOSObject extends COSBase
+{
+
+    private COSBase baseObject;
+
+    private IndirectCOSObject(COSBase wrapped)
+    {
+        this.baseObject = wrapped;
+    }
+
+    @Override
+    public COSBase getCOSObject()
+    {
+        return baseObject;
+    }
+
+    @Override
+    public void accept(COSVisitor visitor) throws IOException
+    {
+        baseObject.accept(visitor);
+    }
+
+    /**
+     * Factory method for an object that will be written as an indirect object.
+     * 
+     * @param wrapped
+     * @return the new instance
+     */
+    public static IndirectCOSObject asIndirectObject(COSObjectable wrapped)
+    {
+        return new IndirectCOSObject(
+                Optional.ofNullable(wrapped).orElse(COSNull.NULL).getCOSObject());
+    }
+
+}


=====================================
src/main/java/org/sejda/sambox/cos/IndirectCOSObjectIdentifier.java
=====================================
@@ -58,7 +58,8 @@ public final class IndirectCOSObjectIdentifier
     @Override
     public int hashCode()
     {
-        return Long.hashCode(objectIdentifier.hashCode() + ownerIdentifier.hashCode());
+        return Long
+                .hashCode((long) objectIdentifier.hashCode() + (long) ownerIdentifier.hashCode());
     }
 
     @Override


=====================================
src/main/java/org/sejda/sambox/input/BaseCOSParser.java
=====================================
@@ -49,7 +49,6 @@ abstract class BaseCOSParser extends SourceReader
     private static final Logger LOG = LoggerFactory.getLogger(BaseCOSParser.class);
 
     public static final String ENDOBJ = "endobj";
-    public static final String OBJ = "obj";
     public static final String STREAM = "stream";
     public static final String ENDSTREAM = "endstream";
 


=====================================
src/main/java/org/sejda/sambox/input/ObjectsFullScanner.java
=====================================
@@ -36,7 +36,8 @@ import org.slf4j.LoggerFactory;
 class ObjectsFullScanner
 {
     private static final Logger LOG = LoggerFactory.getLogger(ObjectsFullScanner.class);
-    private static final Pattern OBJECT_DEF_PATTERN = Pattern.compile("^(\\d+)[\\s](\\d+)[\\s]obj");
+    private static final Pattern OBJECT_DEF_PATTERN = Pattern
+            .compile("^(\\d+)[\\s]+(\\d+)[\\s]+obj");
 
     private Xref xref = new Xref();
     private SourceReader reader;


=====================================
src/main/java/org/sejda/sambox/input/XrefFullScanner.java
=====================================
@@ -138,7 +138,7 @@ class XrefFullScanner
 
     private void parseFoundXrefTable(long offset) throws IOException
     {
-        LOG.debug("Found xref table at " + offset);
+        LOG.debug("Found xref table at {}", offset);
         trailer.xrefOffset(offset);
         xrefTableParser.parse(offset);
     }
@@ -157,7 +157,7 @@ class XrefFullScanner
         if (found instanceof COSDictionary
                 && COSName.XREF.equals(((COSDictionary) found).getItem(COSName.TYPE)))
         {
-            LOG.debug("Found xref stream at " + offset);
+            LOG.debug("Found xref stream at {}", offset);
             trailer.xrefOffset(offset);
             parseFoundXrefStream((COSDictionary) found);
         }


=====================================
src/main/java/org/sejda/sambox/input/XrefParser.java
=====================================
@@ -17,9 +17,9 @@
 package org.sejda.sambox.input;
 
 import static java.util.Objects.nonNull;
+import static org.sejda.commons.util.RequireUtils.requireIOCondition;
 import static org.sejda.sambox.input.AbstractXrefTableParser.TRAILER;
 import static org.sejda.sambox.input.AbstractXrefTableParser.XREF;
-import static org.sejda.commons.util.RequireUtils.requireIOCondition;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -126,7 +126,7 @@ class XrefParser
                         {
                             if (line.startsWith(TRAILER))
                             {
-                                LOG.debug("Parsing trailer at " + offset);
+                                LOG.debug("Parsing trailer at {}", offset);
                                 parser.position(offset);
                                 parser.skipExpected(TRAILER);
                                 parser.skipSpaces();
@@ -139,7 +139,7 @@ class XrefParser
                                 try
                                 {
                                     // we do our best to make sure we have a catalog even in corrupted docs
-                                    LOG.debug("Parsing potential Catalog at " + lastObjectOffset);
+                                    LOG.debug("Parsing potential Catalog at {}", lastObjectOffset);
                                     parser.position(lastObjectOffset);
                                     parser.skipIndirectObjectDefinition();
                                     parser.skipSpaces();
@@ -160,7 +160,7 @@ class XrefParser
                             }
                             else if (line.startsWith(XREF))
                             {
-                                LOG.debug("Found xref at " + offset);
+                                LOG.debug("Found xref at {}", offset);
                                 trailer.xrefOffset(offset);
                             }
                         }
@@ -175,6 +175,7 @@ class XrefParser
                 // and we consider it more reliable compared to what was found in the somehow broken xrefs
                 objectsFullScanner.entries().values().stream().forEach(parser.provider()::addEntry);
             }
+            trailer.setFallbackScanStatus(xrefScanStatus.name());
         }
     }
 
@@ -203,7 +204,7 @@ class XrefParser
             parser.position(startPosition + relativeIndex + STARTXREF.length());
             parser.skipSpaces();
             long xrefOffset = parser.readLong();
-            LOG.debug("Found xref offset at " + xrefOffset);
+            LOG.debug("Found xref offset at {}", xrefOffset);
             return xrefOffset;
         }
         catch (IOException e)


=====================================
src/main/java/org/sejda/sambox/output/DefaultPDFWriter.java
=====================================
@@ -28,7 +28,9 @@ import java.util.Optional;
 
 import org.sejda.commons.util.IOUtils;
 import org.sejda.sambox.cos.COSDictionary;
+import org.sejda.sambox.cos.COSInteger;
 import org.sejda.sambox.cos.COSName;
+import org.sejda.sambox.cos.DirectCOSObject;
 import org.sejda.sambox.cos.IndirectCOSObjectReference;
 import org.sejda.sambox.xref.XrefEntry;
 import org.slf4j.Logger;
@@ -117,7 +119,8 @@ class DefaultPDFWriter implements Closeable
     {
         LOG.trace("Writing trailer");
         sanitizeTrailer(trailer, prev);
-        trailer.setLong(COSName.SIZE, writer.context().highestObjectNumber() + 1);
+        trailer.setItem(COSName.SIZE, DirectCOSObject
+                .asDirectObject(COSInteger.get(writer.context().highestObjectNumber() + 1)));
         writer.write("trailer".getBytes(StandardCharsets.US_ASCII));
         writer.writeEOL();
         trailer.getCOSObject().accept(writer.writer());
@@ -151,8 +154,8 @@ class DefaultPDFWriter implements Closeable
         long startxref = writer().offset();
         LOG.debug("Writing xref stream at offset " + startxref);
         sanitizeTrailer(trailer, prev);
-        XrefEntry entry = XrefEntry
-                .inUseEntry(writer.context().highestObjectNumber() + 1, startxref, 0);
+        XrefEntry entry = XrefEntry.inUseEntry(writer.context().highestObjectNumber() + 1,
+                startxref, 0);
         writer.context().addWritten(entry);
         writer.writeObject(new IndirectCOSObjectReference(entry.getObjectNumber(),
                 entry.getGenerationNumber(), new XrefStream(trailer, writer.context())));


=====================================
src/main/java/org/sejda/sambox/output/IndirectObjectsWriter.java
=====================================
@@ -117,7 +117,7 @@ class IndirectObjectsWriter implements Closeable
         writer.writer().writeEOL();
         writer.writer().write(ENDOBJ);
         writer.writer().writeEOL();
-        LOG.trace("Written object " + object.xrefEntry());
+        LOG.trace("Written object {}", object.xrefEntry());
     }
 
     /**


=====================================
src/main/java/org/sejda/sambox/output/IndirectReferencesAwareCOSWriter.java
=====================================
@@ -16,6 +16,8 @@
  */
 package org.sejda.sambox.output;
 
+import static java.util.Optional.ofNullable;
+
 import java.io.IOException;
 
 import org.sejda.io.BufferedCountingChannelWriter;
@@ -53,20 +55,7 @@ class IndirectReferencesAwareCOSWriter extends DefaultCOSWriter
     @Override
     void writeValue(COSBase value) throws IOException
     {
-        if (context.hasIndirectReferenceFor(value))
-        {
-            context.getIndirectReferenceFor(value).accept(this);
-        }
-        else
-        {
-            value.accept(this);
-        }
-    }
-
-    @Override
-    public void close() throws IOException
-    {
-        super.close();
+        ofNullable((COSBase) context.getIndirectReferenceFor(value)).orElse(value).accept(this);
     }
 
 }


=====================================
src/main/java/org/sejda/sambox/output/ObjectsStreamPDFBodyObjectsWriter.java
=====================================
@@ -62,8 +62,7 @@ public class ObjectsStreamPDFBodyObjectsWriter implements PDFBodyObjectsWriter
         requireNotNullArg(delegate, "Delegate writer cannot be null");
         this.context = context;
         this.delegate = delegate;
-        currentStream = new ObjectsStream(context);
-        context.createIndirectReferenceFor(currentStream);
+        this.currentStream = new ObjectsStream(context);
     }
 
     @Override
@@ -76,31 +75,29 @@ public class ObjectsStreamPDFBodyObjectsWriter implements PDFBodyObjectsWriter
         }
         else
         {
-            IndirectCOSObjectReference streamRef = context.getIndirectReferenceFor(currentStream);
             context.addWritten(
                     CompressedXrefEntry.compressedEntry(ref.xrefEntry().getObjectNumber(),
-                            streamRef.xrefEntry().getObjectNumber(), currentStream.counter));
+                            currentStream.reference().xrefEntry().getObjectNumber(),
+                            currentStream.counter));
             currentStream.addItem(ref);
-            LOG.trace("Added ref {} to object stream {}", ref, streamRef);
+            LOG.trace("Added ref {} to object stream {}", ref, currentStream.reference());
         }
         if (currentStream.isFull())
         {
             doWriteObjectsStream();
             currentStream = new ObjectsStream(context);
-            context.createIndirectReferenceFor(currentStream);
         }
 
     }
 
     private void doWriteObjectsStream() throws IOException
     {
-        IndirectCOSObjectReference ref = context.getIndirectReferenceFor(currentStream);
-        LOG.debug("Writing object stream {}", ref);
+        LOG.debug("Writing object stream {}", currentStream.reference());
         currentStream.prepareForWriting();
         IndirectCOSObjectReference length = context
                 .createNonStorableInObjectStreamIndirectReference();
         currentStream.setItem(COSName.LENGTH, length);
-        delegate.writeObject(ref);
+        delegate.writeObject(currentStream.reference());
         LOG.trace("Writing object stream length {}", length);
         delegate.writeObject(length);
     }
@@ -130,6 +127,7 @@ public class ObjectsStreamPDFBodyObjectsWriter implements PDFBodyObjectsWriter
         private FastByteArrayOutputStream data = new FastByteArrayOutputStream();
         private DefaultCOSWriter dataWriter;
         private InputStream filtered;
+        private IndirectCOSObjectReference reference;
 
         public ObjectsStream(PDFWriteContext context)
         {
@@ -149,6 +147,7 @@ public class ObjectsStreamPDFBodyObjectsWriter implements PDFBodyObjectsWriter
                     // nothing
                 }
             };
+            this.reference = context.createIndirectReferenceFor(this);
         }
 
         public boolean hasItems()
@@ -194,6 +193,11 @@ public class ObjectsStreamPDFBodyObjectsWriter implements PDFBodyObjectsWriter
             this.data = null;
         }
 
+        IndirectCOSObjectReference reference()
+        {
+            return this.reference;
+        }
+
         @Override
         public void close() throws IOException
         {


=====================================
src/main/java/org/sejda/sambox/output/PDFBodyWriter.java
=====================================
@@ -34,6 +34,7 @@ import org.sejda.sambox.cos.COSName;
 import org.sejda.sambox.cos.COSNull;
 import org.sejda.sambox.cos.COSStream;
 import org.sejda.sambox.cos.COSVisitor;
+import org.sejda.sambox.cos.IndirectCOSObject;
 import org.sejda.sambox.cos.IndirectCOSObjectReference;
 import org.sejda.sambox.input.ExistingIndirectCOSObject;
 import org.sejda.sambox.input.IncrementablePDDocument;
@@ -130,7 +131,7 @@ class PDFBodyWriter implements COSVisitor, Closeable
         for (int i = 0; i < array.size(); i++)
         {
             COSBase item = ofNullable(array.get(i)).orElse(COSNull.NULL);
-            if (item instanceof ExistingIndirectCOSObject || item instanceof COSDictionary)
+            if (shouldBeIndirect(item))
             {
                 onPotentialIndirectObject(item);
             }
@@ -147,8 +148,7 @@ class PDFBodyWriter implements COSVisitor, Closeable
         for (COSName key : value.keySet())
         {
             COSBase item = ofNullable(value.getItem(key)).orElse(COSNull.NULL);
-            if (item instanceof ExistingIndirectCOSObject || item instanceof COSDictionary
-                    || COSName.THREADS.equals(key))
+            if (shouldBeIndirect(item) || COSName.THREADS.equals(key))
             {
                 onPotentialIndirectObject(item);
             }
@@ -180,6 +180,12 @@ class PDFBodyWriter implements COSVisitor, Closeable
 
     }
 
+    private boolean shouldBeIndirect(COSBase item)
+    {
+        return (item instanceof ExistingIndirectCOSObject || item instanceof COSDictionary
+                || item instanceof IndirectCOSObject);
+    }
+
     /**
      * Called during the visit on the objects graph, when a potential indirect object is met. Default implementation
      * creates a new indirect reference for it.
@@ -196,7 +202,7 @@ class PDFBodyWriter implements COSVisitor, Closeable
     {
         if (!context.hasIndirectReferenceFor(item))
         {
-            stack.add(context.getOrCreateIndirectReferenceFor(item));
+            stack.add(context.createIndirectReferenceFor(item));
         }
     }
 


=====================================
src/main/java/org/sejda/sambox/output/PDFWriteContext.java
=====================================
@@ -31,8 +31,6 @@ import java.util.concurrent.ConcurrentSkipListMap;
 import java.util.function.Function;
 
 import org.sejda.sambox.cos.COSBase;
-import org.sejda.sambox.cos.COSName;
-import org.sejda.sambox.cos.COSNull;
 import org.sejda.sambox.cos.COSObjectKey;
 import org.sejda.sambox.cos.IndirectCOSObjectIdentifier;
 import org.sejda.sambox.cos.IndirectCOSObjectReference;
@@ -120,32 +118,24 @@ class PDFWriteContext
     private IndirectCOSObjectReference createNewReference(COSBase item,
             Function<COSBase, IndirectCOSObjectReference> supplier)
     {
-        // It's an existing indirect object
-        if (item instanceof ExistingIndirectCOSObject)
+        IndirectCOSObjectReference newRef = supplier.apply(item);
+        LOG.trace("Created new indirect reference {} for {}", newRef, item.id());
+        // It's not an existing indirect object
+        if (!(item instanceof ExistingIndirectCOSObject))
         {
-            ExistingIndirectCOSObject existingItem = (ExistingIndirectCOSObject) item;
-            IndirectCOSObjectReference newRef = supplier.apply(item);
-            LOG.trace("Created new indirect reference {} replacing the existing one {}", newRef,
-                    existingItem.id());
-            // if a COSName was indirect in the original doc we write it as indirect but we don't as indirect every
-            // occurrence of it, just this
-            if (!(item.getCOSObject() instanceof COSName))
-            {
-                lookupNewRef.put(existingItem.id(), newRef);
-            }
-            return newRef;
-
+            // it's a new COSBase
+            item.idIfAbsent(new IndirectCOSObjectIdentifier(newRef.xrefEntry().key(), contextId));
         }
-        if (item instanceof COSNull)
+        // we store the ID if the item reference can be reused. At this point we should always have an id since we get
+        // here only with ExistingIndirectCOSObject, COSDictionary or IndirectCOSObject
+        if (item.hasId())
         {
-            // we don't associate any id or store any lookup for COSNull
-            return supplier.apply(item);
+            lookupNewRef.put(item.id(), newRef);
+        }
+        else
+        {
+            LOG.warn("Unexpected indirect reference for {}", item);
         }
-        // it's a new COSBase
-        IndirectCOSObjectReference newRef = supplier.apply(item);
-        LOG.trace("Created new indirect reference '{}' ", newRef);
-        item.idIfAbsent(new IndirectCOSObjectIdentifier(newRef.xrefEntry().key(), contextId));
-        lookupNewRef.put(item.id(), newRef);
         return newRef;
     }
 
@@ -158,22 +148,22 @@ class PDFWriteContext
      */
     IndirectCOSObjectReference getOrCreateIndirectReferenceFor(COSBase item)
     {
-        if (hasIndirectReferenceFor(item))
-        {
-            // I met it already
-            return lookupNewRef.get(item.id());
-        }
-        return createIndirectReferenceFor(item);
+        return ofNullable(getIndirectReferenceFor(item))
+                .orElseGet(() -> createIndirectReferenceFor(item));
     }
 
     /**
      * @param item
      * @return the {@link IndirectCOSObjectReference} for the given item or null if an
-     * {@link IndirectCOSObjectReference} has not been created for the item.
+     * {@link IndirectCOSObjectReference} has not been created for the item or the item has no id.
      */
     IndirectCOSObjectReference getIndirectReferenceFor(COSBase item)
     {
-        return lookupNewRef.get(item.id());
+        if (item.hasId())
+        {
+            return lookupNewRef.get(item.id());
+        }
+        return null;
     }
 
     /**


=====================================
src/main/java/org/sejda/sambox/pdmodel/PDDocument.java
=====================================
@@ -702,5 +702,10 @@ public class PDDocument implements Closeable
     {
         return PDFParser.parse(SeekableSources.seekableSourceFrom(file));
     }
+    
+    public boolean hasParseErrors()
+    {
+        return this.document.getTrailer().getFallbackScanStatus() != null;
+    }
 
 }


=====================================
src/main/java/org/sejda/sambox/pdmodel/graphics/color/PDColorSpace.java
=====================================
@@ -95,12 +95,9 @@ public abstract class PDColorSpace implements COSObjectable
         if (colorSpace.hasId() && resources != null)
         {
             ResourceCache cache = resources.getResourceCache();
-            if (cache != null)
+            if (cache != null && isAllowedCache(result))
             {
-                if (isAllowedCache(result))
-                {
-                    cache.put(colorSpace.id().objectIdentifier, result);
-                }
+                cache.put(colorSpace.id().objectIdentifier, result);
             }
         }
 
@@ -109,15 +106,8 @@ public abstract class PDColorSpace implements COSObjectable
 
     public static boolean isAllowedCache(PDColorSpace colorSpace)
     {
-        if (colorSpace instanceof PDPattern)
-        {
-            // cannot cache PDPattern color spaces in a global cache, they carry page resources
-            return false;
-        }
-        else
-        {
-            return true;
-        }
+        // cannot cache PDPattern color spaces in a global cache, they carry page resources
+        return !(colorSpace instanceof PDPattern);
     }
 
     /**
@@ -136,11 +126,11 @@ public abstract class PDColorSpace implements COSObjectable
     private static PDColorSpace createUncached(COSBase colorSpace, PDResources resources,
             boolean wasDefault, int recursionAccumulator) throws IOException
     {
-        if(recursionAccumulator > 4) 
+        if (recursionAccumulator > 4)
         {
             throw new IOException("Could not create color space, infinite recursion detected");
         }
-        
+
         colorSpace = colorSpace.getCOSObject();
         if (colorSpace instanceof COSName)
         {


=====================================
src/main/java/org/sejda/sambox/pdmodel/graphics/shading/PDShading.java
=====================================
@@ -227,7 +227,10 @@ public abstract class PDShading implements COSObjectable
         {
             COSBase colorSpaceDictionary = dictionary.getDictionaryObject(COSName.CS,
                     COSName.COLORSPACE);
-            colorSpace = PDColorSpace.create(colorSpaceDictionary);
+            if (colorSpaceDictionary != null) 
+            {
+                colorSpace = PDColorSpace.create(colorSpaceDictionary);
+            }
         }
         return colorSpace;
     }


=====================================
src/main/java/org/sejda/sambox/xref/FileTrailer.java
=====================================
@@ -29,6 +29,7 @@ import org.sejda.sambox.pdmodel.common.PDDictionaryWrapper;
 public class FileTrailer extends PDDictionaryWrapper
 {
     private long xrefOffset = -1;
+    private String fallbackScanStatus = null; 
 
     public FileTrailer()
     {
@@ -57,4 +58,12 @@ public class FileTrailer extends PDDictionaryWrapper
     {
         return COSName.XREF.equals(getCOSObject().getCOSName(COSName.TYPE));
     }
+
+    public String getFallbackScanStatus() {
+        return fallbackScanStatus;
+    }
+
+    public void setFallbackScanStatus(String fallbackScanStatus) {
+        this.fallbackScanStatus = fallbackScanStatus;
+    }
 }



View it on GitLab: https://salsa.debian.org/java-team/libsambox-java/-/compare/79c7edd2fbb5a8fdde5359e3eb96e9b09d564465...084764886c4e232a618efe8dc06123961f29af56

-- 
View it on GitLab: https://salsa.debian.org/java-team/libsambox-java/-/compare/79c7edd2fbb5a8fdde5359e3eb96e9b09d564465...084764886c4e232a618efe8dc06123961f29af56
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20211001/78479337/attachment.htm>


More information about the pkg-java-commits mailing list