[Git][java-team/libsambox-java][upstream] New upstream version 2.2.19

Markus Koschany (@apo) gitlab at salsa.debian.org
Mon Sep 6 21:03:57 BST 2021



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


Commits:
62acf1ec by Markus Koschany at 2021-09-06T21:59:19+02:00
New upstream version 2.2.19
- - - - -


12 changed files:

- .travis.yml
- pom.xml
- src/main/java/org/sejda/sambox/contentstream/operator/color/SetNonStrokingColorSpace.java
- src/main/java/org/sejda/sambox/contentstream/operator/color/SetStrokingColorSpace.java
- src/main/java/org/sejda/sambox/output/WriteOption.java
- src/main/java/org/sejda/sambox/pdmodel/PDDocument.java
- src/main/java/org/sejda/sambox/pdmodel/PDDocumentInformation.java
- src/main/java/org/sejda/sambox/pdmodel/common/PDNameTreeNode.java
- src/main/java/org/sejda/sambox/pdmodel/graphics/color/PDColorSpace.java
- src/main/java/org/sejda/sambox/pdmodel/graphics/image/PDImageXObject.java
- src/main/java/org/sejda/sambox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
- src/main/java/org/sejda/sambox/rendering/PageDrawer.java


Changes:

=====================================
.travis.yml
=====================================
@@ -1,7 +1,4 @@
 language: java
-arch:
-    - AMD64
-    - ppc64le
 sudo: false
 jdk:
   - openjdk8


=====================================
pom.xml
=====================================
@@ -5,7 +5,7 @@
 	<artifactId>sambox</artifactId>
 	<packaging>jar</packaging>
 	<name>sambox</name>
-	<version>2.2.11</version>
+	<version>2.2.19</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.11</tag>
+		<tag>v2.2.19</tag>
 	</scm>
 
 	<developers>


=====================================
src/main/java/org/sejda/sambox/contentstream/operator/color/SetNonStrokingColorSpace.java
=====================================
@@ -19,6 +19,8 @@ package org.sejda.sambox.contentstream.operator.color;
 import java.io.IOException;
 import java.util.List;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.sejda.sambox.contentstream.operator.Operator;
 import org.sejda.sambox.contentstream.operator.OperatorName;
 import org.sejda.sambox.contentstream.operator.OperatorProcessor;
@@ -34,14 +36,34 @@ import org.sejda.sambox.pdmodel.graphics.color.PDColorSpace;
  */
 public class SetNonStrokingColorSpace extends OperatorProcessor
 {
+
+    private static final Log LOGGER = LogFactory.getLog(SetStrokingColorSpace.class);
+    
     @Override
     public void process(Operator operator, List<COSBase> arguments) throws IOException
     {
-        COSName name = (COSName) arguments.get(0);
+        if(arguments == null || arguments.size() == 0)
+        {
+            LOGGER.warn("Ignoring SetNonStrokingColorSpace operator without operands");
+            return;
+        }
+        
+        COSBase base = arguments.get(0);
 
-        PDColorSpace cs = getContext().getResources().getColorSpace(name);
-        getContext().getGraphicsState().setNonStrokingColorSpace(cs);
-        getContext().getGraphicsState().setNonStrokingColor(cs.getInitialColor());
+        if (base instanceof COSName) 
+        {
+            COSName name = (COSName) base;
+            try 
+            {
+                PDColorSpace cs = getContext().getResources().getColorSpace(name);
+                getContext().getGraphicsState().setNonStrokingColorSpace(cs);
+                getContext().getGraphicsState().setNonStrokingColor(cs.getInitialColor());
+            }
+            catch (IOException ex)
+            {
+                LOGGER.warn("Ignoring SetNonStrokingColorSpace operator, parsing colorspace caused an error", ex);
+            }
+        }
     }
 
     @Override


=====================================
src/main/java/org/sejda/sambox/contentstream/operator/color/SetStrokingColorSpace.java
=====================================
@@ -19,6 +19,8 @@ package org.sejda.sambox.contentstream.operator.color;
 import java.io.IOException;
 import java.util.List;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.sejda.sambox.contentstream.operator.Operator;
 import org.sejda.sambox.contentstream.operator.OperatorName;
 import org.sejda.sambox.contentstream.operator.OperatorProcessor;
@@ -34,15 +36,31 @@ import org.sejda.sambox.pdmodel.graphics.color.PDColorSpace;
  */
 public class SetStrokingColorSpace extends OperatorProcessor
 {
+    private static final Log LOGGER = LogFactory.getLog(SetStrokingColorSpace.class);
+    
     @Override
     public void process(Operator operator, List<COSBase> arguments) throws IOException
     {
+        if(arguments == null || arguments.size() == 0)
+        {
+            LOGGER.warn("Ignoring SetStrokingColorSpace operator without operands");
+            return;
+        }
+
         COSBase base = arguments.get(0);
         if (base instanceof COSName)
         {
-            PDColorSpace cs = getContext().getResources().getColorSpace((COSName) base);
-            getContext().getGraphicsState().setStrokingColorSpace(cs);
-            getContext().getGraphicsState().setStrokingColor(cs.getInitialColor());
+            COSName name = (COSName) base;
+            try 
+            {
+                PDColorSpace cs = getContext().getResources().getColorSpace(name);
+                getContext().getGraphicsState().setStrokingColorSpace(cs);
+                getContext().getGraphicsState().setStrokingColor(cs.getInitialColor());
+            } 
+            catch (IOException ex)
+            {
+                LOGGER.warn("Ignoring SetStrokingColorSpace operator, parsing colorspace caused an error", ex);
+            }
         }
     }
 


=====================================
src/main/java/org/sejda/sambox/output/WriteOption.java
=====================================
@@ -38,5 +38,9 @@ public enum WriteOption
     /**
      * Adds a Flate filter to the streams if not already there
      */
-    COMPRESS_STREAMS;
+    COMPRESS_STREAMS,
+    /**
+     * Does not automatically update metadata modified date and producer when saving
+     */
+    NO_METADATA_PRODUCER_MODIFIED_DATE_UPDATE;
 }


=====================================
src/main/java/org/sejda/sambox/pdmodel/PDDocument.java
=====================================
@@ -39,6 +39,7 @@ import java.util.HashSet;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
+import java.util.Arrays;
 
 import org.apache.fontbox.ttf.TrueTypeFont;
 import org.sejda.commons.util.IOUtils;
@@ -591,8 +592,13 @@ public class PDDocument implements Closeable
     {
         requireOpen();
 
-        getDocumentInformation().setProducer(SAMBox.PRODUCER);
-        getDocumentInformation().setModificationDate(Calendar.getInstance());
+        if( Arrays.stream(options).anyMatch(i -> i == WriteOption.NO_METADATA_PRODUCER_MODIFIED_DATE_UPDATE)) {
+            // does not update producer and last modification date
+        } else {
+            getDocumentInformation().setProducer(SAMBox.PRODUCER);
+            getDocumentInformation().setModificationDate(Calendar.getInstance());    
+        }
+        
         for (Subsettable font : fontsToSubset)
         {
             try {


=====================================
src/main/java/org/sejda/sambox/pdmodel/PDDocumentInformation.java
=====================================
@@ -275,6 +275,11 @@ public class PDDocumentInformation extends PDDictionaryWrapper
     {
         getCOSObject().setString(fieldName, fieldValue);
     }
+    
+    public void removeMetadataField(String fieldName)
+    {
+        getCOSObject().removeItem(COSName.getPDFName(fieldName));
+    }
 
     /**
      * This will set the trapped of the document.  This will be


=====================================
src/main/java/org/sejda/sambox/pdmodel/common/PDNameTreeNode.java
=====================================
@@ -284,6 +284,12 @@ public abstract class PDNameTreeNode<T extends COSObjectable> implements COSObje
             for (int i = 0; i < namesArray.size(); i += 2)
             {
                 COSString key = (COSString) namesArray.getObject(i);
+                if(i + 1 >= namesArray.size())
+                {
+                    // some invalid NAMES arrays have only the key without a value
+                    LOG.warn("Found key without value in NAMES array: " + key.getString() + ", at index: " + i);
+                    continue;
+                }
                 COSBase cosValue = namesArray.getObject(i + 1);
                 names.put(key.getString(), convertCOSToPD(cosValue));
             }


=====================================
src/main/java/org/sejda/sambox/pdmodel/graphics/color/PDColorSpace.java
=====================================
@@ -90,7 +90,7 @@ public abstract class PDColorSpace implements COSObjectable
             }
         }
 
-        PDColorSpace result = createUncached(colorSpace, resources, wasDefault);
+        PDColorSpace result = createUncached(colorSpace, resources, wasDefault, 0);
 
         if (colorSpace.hasId() && resources != null)
         {
@@ -128,13 +128,19 @@ public abstract class PDColorSpace implements COSObjectable
      * @param colorSpace the color space COS object
      * @param resources the current resources.
      * @param wasDefault if current color space was used by a default color space.
+     * @param recursionAccumulator counts the levels of recursion for this method, to avoid going too deep
      * @return a new color space.
      * @throws MissingResourceException if the color space is missing in the resources dictionary
      * @throws IOException if the color space is unknown or cannot be created.
      */
     private static PDColorSpace createUncached(COSBase colorSpace, PDResources resources,
-            boolean wasDefault) throws IOException
+            boolean wasDefault, int recursionAccumulator) throws IOException
     {
+        if(recursionAccumulator > 4) 
+        {
+            throw new IOException("Could not create color space, infinite recursion detected");
+        }
+        
         colorSpace = colorSpace.getCOSObject();
         if (colorSpace instanceof COSName)
         {
@@ -252,7 +258,7 @@ public abstract class PDColorSpace implements COSObjectable
                     || name == COSName.DEVICEGRAY)
             {
                 // not allowed in an array, but we sometimes encounter these regardless
-                return createUncached(name, resources, wasDefault);
+                return createUncached(name, resources, wasDefault, recursionAccumulator + 1);
             }
             else
             {
@@ -266,7 +272,7 @@ public abstract class PDColorSpace implements COSObjectable
             {
                 LOG.warn("Found invalid color space defined as dictionary {}", csAsDic);
                 return createUncached(csAsDic.getDictionaryObject(COSName.COLORSPACE), resources,
-                        wasDefault);
+                        wasDefault, recursionAccumulator + 1);
             }
         }
 


=====================================
src/main/java/org/sejda/sambox/pdmodel/graphics/image/PDImageXObject.java
=====================================
@@ -49,6 +49,8 @@ import org.sejda.sambox.pdmodel.common.PDStream;
 import org.sejda.sambox.pdmodel.graphics.PDXObject;
 import org.sejda.sambox.pdmodel.graphics.color.PDColorSpace;
 import org.sejda.sambox.pdmodel.graphics.color.PDDeviceGray;
+import org.sejda.sambox.pdmodel.graphics.color.PDDeviceRGB;
+import org.sejda.sambox.pdmodel.graphics.color.PDJPXColorSpace;
 import org.sejda.sambox.util.filetypedetector.FileType;
 import org.sejda.sambox.util.filetypedetector.FileTypeDetector;
 import org.slf4j.Logger;
@@ -303,7 +305,12 @@ public final class PDImageXObject extends PDXObject implements PDImage
         {
             // PDFBOX-4267: process /Matte
             // convert to RGB
-            return getColorSpace().toRGB(matte);
+            PDColorSpace colorSpace = getColorSpace();
+            if(colorSpace instanceof PDJPXColorSpace) {
+                // #125 JPX color spaces don't support drawing
+                colorSpace = PDDeviceRGB.INSTANCE; 
+            }
+            return colorSpace.toRGB(matte);
         }
         return null;
     }


=====================================
src/main/java/org/sejda/sambox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
=====================================
@@ -795,7 +795,7 @@ public class AppearanceGeneratorHelper
 
             contents.newLineAtOffset(contentRect.getLowerLeftX(), yTextPos);
             contents.setFont(font, fontSize);
-            contents.showText(options.get(i));
+            contents.showText(replaceTabChars(options.get(i)));
 
             if (i != (numOptions - 1))
             {
@@ -803,6 +803,12 @@ public class AppearanceGeneratorHelper
             }
         }
     }
+    
+    private String replaceTabChars(String input)
+    {
+        // avoid java.lang.IllegalArgumentException: U+0009 ('controlHT') is not available in this font XYZ
+        return input.replace("\t", "    ");
+    }
 
     private float calculateLineHeight(PDFont font, float fontScaleY) throws IOException
     {


=====================================
src/main/java/org/sejda/sambox/rendering/PageDrawer.java
=====================================
@@ -743,7 +743,7 @@ public class PageDrawer extends PDFGraphicsStreamEngine
         {
             for (int i = 0; i < dashArray.length; ++i)
             {
-                if (Float.isInfinite(dashArray[i]) || Float.isNaN(dashArray[i]))
+                if (Float.isInfinite(dashArray[i]) || Float.isNaN(dashArray[i]) || dashArray[i] < 0)
                 {
                     dashArray = null;
                     break;



View it on GitLab: https://salsa.debian.org/java-team/libsambox-java/-/commit/62acf1ecb0650a1cec77810737cb5c869aad594d

-- 
View it on GitLab: https://salsa.debian.org/java-team/libsambox-java/-/commit/62acf1ecb0650a1cec77810737cb5c869aad594d
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/20210906/89d93406/attachment.htm>


More information about the pkg-java-commits mailing list