Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package pdftk for openSUSE:Factory checked in at 2021-12-28 12:26:31 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/pdftk (Old) and /work/SRC/openSUSE:Factory/.pdftk.new.2520 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "pdftk" Tue Dec 28 12:26:31 2021 rev:7 rq:942887 version:3.3.2 Changes: -------- --- /work/SRC/openSUSE:Factory/pdftk/pdftk.changes 2021-11-01 22:21:03.479225853 +0100 +++ /work/SRC/openSUSE:Factory/.pdftk.new.2520/pdftk.changes 2021-12-28 12:27:08.976508116 +0100 @@ -1,0 +2,11 @@ +Tue Dec 21 07:24:42 UTC 2021 - Sebastian Wagner <[email protected]> + +- update to version 3.3.2: + - Fixed + - Crash with inputs that contain null pointers + - Support reading xfdf forms from stdin + - Crash with xdf forms with no catalog + - Compatibility with bcprov 1.70 + - Crash with non-conforming inputs + +------------------------------------------------------------------- Old: ---- pdftk-v3.3.1.tar.bz2 New: ---- pdftk-v3.3.2.tar.bz2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ pdftk.spec ++++++ --- /var/tmp/diff_new_pack.QDAwJE/_old 2021-12-28 12:27:09.752508703 +0100 +++ /var/tmp/diff_new_pack.QDAwJE/_new 2021-12-28 12:27:09.756508706 +0100 @@ -18,7 +18,7 @@ Name: pdftk -Version: 3.3.1 +Version: 3.3.2 Release: 0 Summary: A handy tool for manipulating PDF License: GPL-2.0-or-later ++++++ pdftk-v3.3.1.tar.bz2 -> pdftk-v3.3.2.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/.gitlab-ci.yml new/pdftk-v3.3.2/.gitlab-ci.yml --- old/pdftk-v3.3.1/.gitlab-ci.yml 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/.gitlab-ci.yml 2021-12-20 18:20:25.000000000 +0100 @@ -1,12 +1,12 @@ variables: - PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic" - GRADLE_VERSION: "7.1" + PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/pdftk-java" + GRADLE_VERSION: "7.3.2" .ant-job: stage: test except: variables: - - $WEB_JOB != null + - $WEB_JOB != null && $WEB_JOB != "test" image: openjdk:11 before_script: - apt-get update -yqq @@ -16,7 +16,7 @@ extends: .ant-job script: - ant -lib /usr/share/java - - echo -e '#!/bin/bash\njava -cp' `pwd`'/build/jar/pdftk.jar:'`pwd`'/lib/bcprov-jdk15on-1.69.jar:'`pwd`'/lib/commons-lang3-3.12.0.jar com.gitlab.pdftk_java.pdftk "$@"' > /usr/bin/pdftk + - echo -e '#!/bin/bash\njava -cp' `pwd`'/build/jar/pdftk.jar:'`pwd`'/lib/bcprov-jdk15on-1.70.jar:'`pwd`'/lib/commons-lang3-3.12.0.jar com.gitlab.pdftk_java.pdftk "$@"' > /usr/bin/pdftk - chmod +x /usr/bin/pdftk - apt-get install php-mbstring php-xml composer -yqq - git clone --depth 1 https://github.com/marcvinyals/php-pdftk @@ -58,7 +58,7 @@ only: - tags stage: deploy - image: gradle:latest + image: gradle:jdk11 script: - *grade-job-script @@ -72,10 +72,10 @@ paths: - build/libs/pdftk-all.jar -gradle-6.1: +gradle-7.3: extends: .gradle-job variables: - GRADLE_VERSION: "6.1" + GRADLE_VERSION: "7.3" gradle-web: extends: .gradle-job @@ -93,7 +93,7 @@ except: variables: - $WEB_JOB != null - image: gradle:latest + image: gradle:jdk11 script: - gradle spotlessCheck @@ -101,11 +101,12 @@ only: - tags stage: deploy - # cf https://gitlab.com/pdftk-java/pdftk/-/issues/68 before updating - image: ghcr.io/graalvm/graalvm-ce:21.0.0 + # cf https://gitlab.com/pdftk-java/pdftk/-/issues/68 before updating GraalVM + # cf https://gitlab.com/pdftk-java/pdftk/-/issues/113 before updating OracleLinux + image: ghcr.io/graalvm/graalvm-ce:ol7-java11-21.0.0 before_script: - gu install native-image - - microdnf install wget unzip + - yum install -y wget unzip - wget https://services.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zip - unzip gradle-$GRADLE_VERSION-bin.zip script: @@ -124,7 +125,7 @@ variables: - $CI_PIPELINE_SOURCE == "web" && $WEB_JOB == "nativeimage" script: - - ./gradle-$GRADLE_VERSION/bin/gradle -Pgeneratedebuginfo=1 nativeImage + - ./gradle-$GRADLE_VERSION/bin/gradle --warning-mode all -Pgeneratedebuginfo=1 nativeImage - ./build/native-image/pdftk --version artifacts: paths: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/CHANGELOG.md new/pdftk-v3.3.2/CHANGELOG.md --- old/pdftk-v3.3.1/CHANGELOG.md 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/CHANGELOG.md 2021-12-20 18:20:25.000000000 +0100 @@ -1,3 +1,12 @@ +## [3.3.2] - 2021-12-20 + +### Fixed + - Crash with inputs that contain null pointers + - Support reading xfdf forms from stdin + - Crash with xdf forms with no catalog + - Compatibility with bcprov 1.70 + - Crash with non-conforming inputs + ## [3.3.1] - 2021-08-23 ### Fixed diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/README.md new/pdftk-v3.3.2/README.md --- old/pdftk-v3.3.1/README.md 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/README.md 2021-12-20 18:20:25.000000000 +0100 @@ -21,9 +21,9 @@ There are pdftk-java packages available in a few [repositories](https://repology.org/project/pdftk-java/versions), -including Arch, Debian / Ubuntu, Gentoo, Homebrew, MacPorts, and -SUSE. Please refer to the documentation of your package manager for -instructions. +including Arch, Debian / Ubuntu, Fedora / EPEL (for CentOS, RHEL, +Rocky), Gentoo, Homebrew, MacPorts, Mageia, and SUSE. Please refer +to the documentation of your package manager for instructions. :warning: Some distributions provide stable packages that are older than 3.0.4, which fixed many crashes. Consider @@ -43,15 +43,15 @@ manager, but if that is not an option there are pre-built binaries available: - - [Standalone jar](https://gitlab.com/pdftk-java/pdftk/-/packages/generic/v3.3.1/pdftk-all.jar), including dependencies. Requires a JRE at runtime. - - :warning: **Experimental** [Native Image](https://gitlab.com/pdftk-java/pdftk/-/packages/generic/v3.3.1/pdftk) for x86_64 GNU/Linux systems. Does not require any runtime dependencies. + - [Standalone jar](https://gitlab.com/pdftk-java/pdftk/-/jobs/1527259628/artifacts/raw/build/libs/pdftk-all.jar), including dependencies. Requires a JRE at runtime. + - :warning: **Experimental** [Native Image](https://gitlab.com/pdftk-java/pdftk/-/jobs/1527259632/artifacts/raw/build/native-image/pdftk) for x86_64 GNU/Linux systems. Does not require any runtime dependencies. ## Dependencies - jdk >= 1.8 - commons-lang3 - bcprov - - gradle >= 6.1 or ant (build time) + - gradle >= 7.3 or ant (build time) - ivy (optionally for ant, for resolving dependencies at build time) ## Building and running with Gradle @@ -62,10 +62,10 @@ dependencies. The build configuration is relatively simple so it should work with most -versions of gradle since 6.1 (tested 6.1 and 7.1) but if you have problems try +versions of gradle since 7.3 (tested 7.3.2) but if you have problems try installing gradle wrapper at a particular version and then running the wrapper: ``` -gradle wrapper --gradle-version 7.1 +gradle wrapper --gradle-version 7.3 ``` ### Standard jar diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/build.gradle new/pdftk-v3.3.2/build.gradle --- old/pdftk-v3.3.1/build.gradle 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/build.gradle 2021-12-20 18:20:25.000000000 +0100 @@ -1,9 +1,9 @@ plugins { id 'java' id 'application' - id 'com.diffplug.spotless' version '5.14.0' - id 'com.github.johnrengelman.shadow' version '6.1.0' - id "org.mikeneck.graalvm-native-image" version "1.4.1" + id 'com.diffplug.spotless' version '6.0.5' + id 'com.github.johnrengelman.shadow' version '7.1.1' + id 'org.mikeneck.graalvm-native-image' version '1.4.1' } sourceCompatibility = 1.8 @@ -27,12 +27,12 @@ mainClassName = 'com.gitlab.pdftk_java.pdftk' repositories { - jcenter() + mavenCentral() } dependencies { implementation 'org.apache.commons:commons-lang3:3.12.0' - implementation 'org.bouncycastle:bcprov-jdk15on:1.69' + implementation 'org.bouncycastle:bcprov-jdk15on:1.70' } nativeImage { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/ivy.xml new/pdftk-v3.3.2/ivy.xml --- old/pdftk-v3.3.1/ivy.xml 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/ivy.xml 2021-12-20 18:20:25.000000000 +0100 @@ -6,7 +6,7 @@ <conf name="test" extends="build"/> </configurations> <dependencies> - <dependency org="org.bouncycastle" name="bcprov-jdk15on" rev="1.69"/> + <dependency org="org.bouncycastle" name="bcprov-jdk15on" rev="1.70"/> <dependency org="org.apache.commons" name="commons-lang3" rev="3.12.0"/> <dependency org="junit" name="junit" rev="4.12" conf="test"/> <dependency org="com.github.stefanbirkner" name="system-rules" rev="1.19.0" conf="test"/> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/TK_Session.java new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/TK_Session.java --- old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/TK_Session.java 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/TK_Session.java 2021-12-20 18:20:25.000000000 +0100 @@ -1369,8 +1369,6 @@ if (m_output_encryption_strength == encryption_strength.none_enc) { m_output_encryption_strength = encryption_strength.aes128_enc; } - int encryption_type = m_output_encryption_strength.value; - writer_p.setEncryption( m_output_user_pw_pdfdoc, m_output_owner_pw_pdfdoc, @@ -1551,7 +1549,7 @@ done_e }; - class ArgStateMutable { + static class ArgStateMutable { ArgState value; } @@ -1589,6 +1587,7 @@ break; case encrypt_aes128_k: m_output_encryption_strength = encryption_strength.aes128_enc; + break; case filt_uncompress_k: m_output_uncompress_b = true; break; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/attachments.java new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/attachments.java --- old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/attachments.java 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/attachments.java 2021-12-20 18:20:25.000000000 +0100 @@ -37,8 +37,8 @@ import com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfString; import com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfWriter; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; @@ -72,7 +72,7 @@ } static String normalize_pathname(String output_pathname) { - if (output_pathname == "PROMPT") { + if (output_pathname.equals("PROMPT")) { output_pathname = pdftk.prompt_for_filename( "Please enter the directory where you want attachments unpacked:"); @@ -119,21 +119,13 @@ try { byte[] bytes_p = input_reader_p.getStreamBytes((PRStream) f_p); - - if (ask_about_warnings_b) { - // test for existing file by this name - if (pdftk.file_exists(fn)) { - if (!pdftk.confirm_overwrite(fn)) { - System.out.println(" Skipping: " + fn); - return; // <--- return - } - } + OutputStream os = pdftk.get_output_stream_file(fn, ask_about_warnings_b, false); + if (os != null) { + os.write(bytes_p); + os.close(); } - FileOutputStream ofs = new FileOutputStream(fn); - ofs.write(bytes_p); - ofs.close(); - } catch (IOException e) { // error - System.err.println("Error: unable to create the file:"); + } catch (IOException e) { + System.err.println("Error: failed to write attachment file: "); System.err.println(" " + fn); System.err.println(" Skipping."); } @@ -163,7 +155,7 @@ Matcher m = p.matcher(buff); m.matches(); try { - m_input_attach_file_pagenum = Integer.valueOf(m.group(1)); + m_input_attach_file_pagenum = Integer.parseInt(m.group(1)); } catch (NumberFormatException e) { m_input_attach_file_pagenum = 0; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/burst.java new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/burst.java --- old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/burst.java 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/burst.java 2021-12-20 18:20:25.000000000 +0100 @@ -93,7 +93,7 @@ // the filename String output_filename_p = String.format(m_output_filename, ii + 1); - OutputStream ofs_p = pdftk.get_output_stream_file(output_filename_p); + OutputStream ofs_p = pdftk.get_output_stream_file(output_filename_p, false, false); if (ofs_p == null) { ret_val = ErrorCode.PARTIAL; continue; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/FdfReader.java new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/FdfReader.java --- old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/FdfReader.java 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/FdfReader.java 2021-12-20 18:20:25.000000000 +0100 @@ -43,6 +43,9 @@ import java.net.URL; import java.util.ArrayList; import java.util.HashMap; + +import com.gitlab.pdftk_java.com.lowagie.text.exceptions.InvalidPdfException; + /** Reads an FDF form and makes the fields available * @author Paulo Soares ([email protected]) */ @@ -150,11 +153,15 @@ } } - protected void readFields() { + protected void readFields() throws IOException { + PdfDictionary fdf = null; catalog = trailer.getAsDict(PdfName.ROOT); - PdfDictionary fdf = catalog.getAsDict(PdfName.FDF); - if (fdf == null) - return; + if (catalog != null) { + fdf = catalog.getAsDict(PdfName.FDF); + } + if (fdf == null) { + throw new InvalidPdfException("Invalid FDF catalog."); + } readFileSpecification(fdf); PdfArray fld = fdf.getAsArray(PdfName.FIELDS); if (fld == null) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/PdfPKCS7.java new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/PdfPKCS7.java --- old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/PdfPKCS7.java 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/PdfPKCS7.java 2021-12-20 18:20:25.000000000 +0100 @@ -296,7 +296,7 @@ ASN1TaggedObject tagsig = (ASN1TaggedObject)signerInfo.getObjectAt(next); ASN1Sequence sseq = (ASN1Sequence)tagsig.getObject(); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - ASN1OutputStream dout = new ASN1OutputStream(bOut); + ASN1OutputStream dout = ASN1OutputStream.create(bOut); try { ASN1EncodableVector attribute = new ASN1EncodableVector(); for (int k = 0; k < sseq.size(); ++k) { @@ -735,7 +735,7 @@ digest = sig.sign(); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - ASN1OutputStream dout = new ASN1OutputStream(bOut); + ASN1OutputStream dout = ASN1OutputStream.create(bOut); dout.writeObject(new DEROctetString(digest)); dout.close(); @@ -906,7 +906,7 @@ ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - ASN1OutputStream dout = new ASN1OutputStream(bOut); + ASN1OutputStream dout = ASN1OutputStream.create(bOut); dout.writeObject(new DERSequence(whole)); dout.close(); @@ -962,7 +962,7 @@ attribute.add(new DERSequence(v)); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - ASN1OutputStream dout = new ASN1OutputStream(bOut); + ASN1OutputStream dout = ASN1OutputStream.create(bOut); dout.writeObject(new DERSet(attribute)); dout.close(); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/PdfReader.java new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/PdfReader.java --- old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/PdfReader.java 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/PdfReader.java 2021-12-20 18:20:25.000000000 +0100 @@ -921,6 +921,9 @@ protected void readPages() throws IOException { catalog = trailer.getAsDict(PdfName.ROOT); + if (catalog == null) { + throw new InvalidPdfException("catalog not found"); + } rootPages = catalog.getAsDict(PdfName.PAGES); if (rootPages == null) { System.err.println("Warning: failed to read page tree. Corrupt input."); @@ -2823,7 +2826,11 @@ for (int k = 1; k <= pageRefs.size(); ++k) { PdfDictionary page = pageRefs.getPageN(k); PdfObject annotsRef; - PdfArray annots = (PdfArray)getPdfObject(annotsRef = page.get(PdfName.ANNOTS)); + PdfObject annotsObj = getPdfObject(annotsRef = page.get(PdfName.ANNOTS)); + PdfArray annots = null; + if (annotsObj != null && annotsObj.isArray()) { + annots = (PdfArray)annotsObj; + } int annotIdx = lastXrefPartial; releaseLastXrefPartial(); if (annots == null) { @@ -2841,7 +2848,11 @@ if (!commitAnnots || annotsRef.isIndirect()) pageRefs.releasePage(k); } - PdfDictionary outlines = (PdfDictionary)getPdfObjectRelease(catalog.get(PdfName.OUTLINES)); + PdfObject outlinesObj = getPdfObjectRelease(catalog.get(PdfName.OUTLINES)); + PdfDictionary outlines = null; + if (outlinesObj != null && outlinesObj.isDictionary()) { + outlines = (PdfDictionary)outlinesObj; + } if (outlines == null) return; iterateBookmarks(outlines.get(PdfName.FIRST), names); @@ -3443,7 +3454,11 @@ } private void iteratePages(PRIndirectReference rpage) throws IOException { - PdfDictionary page = (PdfDictionary)getPdfObject(rpage); + // pageobj might be a PdfNull in the wild. + // https://gitlab.com/pdftk-java/pdftk/-/issues/110 + PdfObject pageobj = getPdfObject(rpage); + if (!pageobj.isDictionary()) return; + PdfDictionary page = (PdfDictionary)pageobj; PdfArray kidsPR = page.getAsArray(PdfName.KIDS); // reference to a leaf if (kidsPR == null) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/PdfStamperImp.java new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/PdfStamperImp.java --- old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/PdfStamperImp.java 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/com/lowagie/text/pdf/PdfStamperImp.java 2021-12-20 18:20:25.000000000 +0100 @@ -823,21 +823,19 @@ if (!fieldsAdded && partialFlattening.isEmpty()) { for (int page = 1; page <= reader.getNumberOfPages(); ++page) { PdfDictionary pageDic = reader.getPageN(page); - PdfArray annots = (PdfArray)PdfReader.getPdfObject(pageDic.get(PdfName.ANNOTS)); + PdfArray annots = pageDic.getAsArray(PdfName.ANNOTS); if (annots == null) continue; - ArrayList ar = annots.getArrayList(); - for (int idx = 0; idx < ar.size(); ++idx) { - PdfObject annoto = PdfReader.getPdfObject((PdfObject)ar.get(idx)); + for (int idx = 0; idx < annots.size(); ++idx) { + PdfObject annoto = annots.getDirectObject(idx); if ((annoto instanceof PdfIndirectReference) && !annoto.isIndirect()) continue; - PdfDictionary annot = (PdfDictionary)annoto; - if (PdfName.WIDGET.equals(annot.get(PdfName.SUBTYPE))) { - ar.remove(idx); + if (!annoto.isDictionary() || PdfName.WIDGET.equals(((PdfDictionary)annoto).get(PdfName.SUBTYPE))) { + annots.remove(idx); --idx; } } - if (ar.size() == 0) { + if (annots.isEmpty()) { PdfReader.killIndirect(pageDic.get(PdfName.ANNOTS)); pageDic.remove(PdfName.ANNOTS); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/filter.java new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/filter.java --- old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/filter.java 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/filter.java 2021-12-20 18:20:25.000000000 +0100 @@ -37,6 +37,7 @@ import com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfReader; import com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfStamperImp; import com.gitlab.pdftk_java.com.lowagie.text.pdf.XfdfReader; +import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; @@ -128,19 +129,17 @@ } if (!m_form_data_filename.isEmpty()) { // we have form data to process if (m_form_data_filename.equals("-")) { // form data on stdin - // JArray<jbyte>* in_arr= itext::RandomAccessFileOrArray::InputStreamToArray( - // java::System::in ); + byte[] buffer = pdftk.readAllBytes(System.in); // first try fdf try { - fdf_reader_p = new FdfReader(System.in); + fdf_reader_p = new FdfReader(new ByteArrayInputStream(buffer)); } catch (IOException ioe_p) { // file open error // maybe it's xfdf? try { - xfdf_reader_p = new XfdfReader(System.in); + xfdf_reader_p = new XfdfReader(new ByteArrayInputStream(buffer)); } catch (IOException ioe2_p) { // file open error System.err.println("Error: Failed read form data on stdin."); - // ioe_p->printStackTrace(); // debug return ErrorCode.ERROR; } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/pdftk.java new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/pdftk.java --- old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/pdftk.java 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/pdftk.java 2021-12-20 18:20:25.000000000 +0100 @@ -23,21 +23,24 @@ package com.gitlab.pdftk_java; import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.InvalidPathException; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; import java.util.Scanner; public class pdftk { /* TODO: should read from compiler */ - static final String PDFTK_VER = "3.3.1"; + static final String PDFTK_VER = "3.3.2"; static final boolean ASK_ABOUT_WARNINGS = false; static { @@ -102,15 +105,6 @@ return buff.startsWith("y") || buff.startsWith("Y"); } - static boolean file_exists(String filename) { - try { - FileInputStream fp = new FileInputStream(filename); - return true; - } catch (FileNotFoundException e) { - return false; - } - } - static OutputStream get_output_stream(String output_filename, boolean ask_about_warnings_b) { if (output_filename.isEmpty() || output_filename.equals("PROMPT")) { output_filename = prompt_for_filename("Please enter a name for the output:"); @@ -121,32 +115,36 @@ return System.out; } - if (ask_about_warnings_b) { - // test for existing file by this name - boolean output_exists_b = false; - if (file_exists(output_filename)) { - if (!confirm_overwrite(output_filename)) { - // recurse; try again - return get_output_stream("PROMPT", ask_about_warnings_b); - } - } - } - - return get_output_stream_file(output_filename); + return get_output_stream_file(output_filename, ask_about_warnings_b, true); } - static OutputStream get_output_stream_file(String output_filename) { - OutputStream os_p = null; - // attempt to open the stream + static OutputStream get_output_stream_file( + String output_filename, boolean check_overwrite, boolean required) { try { - os_p = new FileOutputStream(output_filename); - } catch (IOException ioe_p) { // file open error + Path p = FileSystems.getDefault().getPath(output_filename); + if (check_overwrite) { + return Files.newOutputStream(p, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW); + } else { + return Files.newOutputStream(p); + } + } catch (FileAlreadyExistsException e) { + if (!confirm_overwrite(output_filename)) { + if (required) { + return get_output_stream("PROMPT", check_overwrite); + } else { + System.err.println(" Skipping: " + output_filename); + } + } + } catch (IOException | InvalidPathException e) { System.err.println("Error: Failed to open output file: "); System.err.println(" " + output_filename); - System.err.println(" No output created."); - os_p = null; + if (required) { + System.err.println(" No output created."); + } else { + System.err.println(" Skipping."); + } } - return os_p; + return null; } static PrintStream get_print_stream(String output_filename, boolean output_utf8_b) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/report.java new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/report.java --- old/pdftk-v3.3.1/java/com/gitlab/pdftk_java/report.java 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/java/com/gitlab/pdftk_java/report.java 2021-12-20 18:20:25.000000000 +0100 @@ -195,7 +195,7 @@ for (int i = 0; i <= option_index; ++i) ret = it.next(); return ret; } - } catch (Exception e) { + } catch (NumberFormatException e) { } } return v; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/patches/commons-lang3-to-text.patch new/pdftk-v3.3.2/patches/commons-lang3-to-text.patch --- old/pdftk-v3.3.1/patches/commons-lang3-to-text.patch 1970-01-01 01:00:00.000000000 +0100 +++ new/pdftk-v3.3.2/patches/commons-lang3-to-text.patch 2021-12-20 18:20:25.000000000 +0100 @@ -0,0 +1,97 @@ +diff --git a/build.gradle b/build.gradle +index 59ad719..2020d69 100644 +--- a/build.gradle ++++ b/build.gradle +@@ -31,7 +31,7 @@ repositories { + } + + dependencies { +- implementation 'org.apache.commons:commons-lang3:3.12.0' ++ implementation 'org.apache.commons:commons-text:1.9' + implementation 'org.bouncycastle:bcprov-jdk15on:1.70' + } + +diff --git a/ivy.xml b/ivy.xml +index 7682148..50f03a5 100644 +--- a/ivy.xml ++++ b/ivy.xml +@@ -7,7 +7,7 @@ + </configurations> + <dependencies> + <dependency org="org.bouncycastle" name="bcprov-jdk15on" rev="1.70"/> +- <dependency org="org.apache.commons" name="commons-lang3" rev="3.12.0"/> ++ <dependency org="org.apache.commons" name="commons-text" rev="1.9"/> + <dependency org="junit" name="junit" rev="4.12" conf="test"/> + <dependency org="com.github.stefanbirkner" name="system-rules" rev="1.19.0" conf="test"/> + <dependency org="org.jacoco" name="org.jacoco.ant" rev="0.8.4" conf="test"/> +diff --git a/java/com/gitlab/pdftk_java/TK_Session.java b/java/com/gitlab/pdftk_java/TK_Session.java +index 8248743..3753b4f 100644 +--- a/java/com/gitlab/pdftk_java/TK_Session.java ++++ b/java/com/gitlab/pdftk_java/TK_Session.java +@@ -38,7 +38,7 @@ import java.util.HashMap; + import java.util.HashSet; + import java.util.regex.Matcher; + import java.util.regex.Pattern; +-import org.apache.commons.lang3.text.WordUtils; ++import org.apache.commons.text.WordUtils; + + class TK_Session { + +diff --git a/java/com/gitlab/pdftk_java/data_import.java b/java/com/gitlab/pdftk_java/data_import.java +index c2fb639..01af277 100644 +--- a/java/com/gitlab/pdftk_java/data_import.java ++++ b/java/com/gitlab/pdftk_java/data_import.java +@@ -34,7 +34,7 @@ import java.io.InputStream; + import java.util.ArrayList; + import java.util.HashMap; + import java.util.Scanner; +-import org.apache.commons.lang3.StringEscapeUtils; ++import org.apache.commons.text.StringEscapeUtils; + + class data_import { + +diff --git a/java/com/gitlab/pdftk_java/pdftk.java b/java/com/gitlab/pdftk_java/pdftk.java +index fdffdc5..489d49f 100644 +--- a/java/com/gitlab/pdftk_java/pdftk.java ++++ b/java/com/gitlab/pdftk_java/pdftk.java +@@ -279,7 +279,7 @@ public class pdftk { + static void describe_missing_library(Throwable error) { + System.err.println("Error: could not load a required library for this operation."); + System.err.println(error); +- System.err.println("Make sure that bcprov and commons-lang3 are installed and included in the"); ++ System.err.println("Make sure that bcprov and commons-text are installed and included in the"); + System.err.println("classpath. See also https://gitlab.com/pdftk-java/pdftk/issues/2."); + } + } +diff --git a/java/com/gitlab/pdftk_java/report.java b/java/com/gitlab/pdftk_java/report.java +index 182f05a..5c9ad94 100644 +--- a/java/com/gitlab/pdftk_java/report.java ++++ b/java/com/gitlab/pdftk_java/report.java +@@ -41,9 +41,9 @@ import java.util.Iterator; + import java.util.LinkedHashSet; + import java.util.List; + import java.util.Set; +-import org.apache.commons.lang3.StringEscapeUtils; +-import org.apache.commons.lang3.text.translate.CharSequenceTranslator; +-import org.apache.commons.lang3.text.translate.NumericEntityEscaper; ++import org.apache.commons.text.StringEscapeUtils; ++import org.apache.commons.text.translate.CharSequenceTranslator; ++import org.apache.commons.text.translate.NumericEntityEscaper; + + class report { + +diff --git a/pom.xml b/pom.xml +index 19b9f04..621f520 100644 +--- a/pom.xml ++++ b/pom.xml +@@ -14,8 +14,8 @@ + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> +- <artifactId>commons-lang3</artifactId> +- <version>3.12.0</version> ++ <artifactId>commons-text</artifactId> ++ <version>1.9</version> + </dependency> + <dependency> + <groupId>junit</groupId> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/pom.xml new/pdftk-v3.3.2/pom.xml --- old/pdftk-v3.3.1/pom.xml 1970-01-01 01:00:00.000000000 +0100 +++ new/pdftk-v3.3.2/pom.xml 2021-12-20 18:20:25.000000000 +0100 @@ -0,0 +1,112 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <!-- The Basics --> + <groupId>com.gitlab.pdftk-java</groupId> + <version>3.3.2</version> + <artifactId>pdftk-java</artifactId> + <packaging>jar</packaging> + <dependencies> + <dependency> + <groupId>org.bouncycastle</groupId> + <artifactId>bcprov-jdk15on</artifactId> + <version>1.70</version> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.12.0</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.github.stefanbirkner</groupId> + <artifactId>system-rules</artifactId> + <version>1.19.0</version> + <scope>test</scope> + </dependency> + </dependencies> + <properties> + <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>1.8</maven.compiler.target> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <!-- Build Settings --> + <build> + <sourceDirectory>java</sourceDirectory> + <testSourceDirectory>test</testSourceDirectory> + <resources> + <resource> + <directory>java</directory> + <includes> + <include>**/*.afm</include> + <include>**/*.txt</include> + </includes> + </resource> + </resources> + <plugins> + <plugin> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> + <version>5.3.0</version> + <executions> + <execution> + <goals> + <goal>bnd-process</goal> + </goals> + </execution> + </executions> + <configuration> + <bnd> + Main-Class: com.gitlab.pdftk_java.pdftk + </bnd> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>3.2.0</version> + <configuration> + <archive> + <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> + </archive> + </configuration> + </plugin> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.8.4</version> + <executions> + <execution> + <id>default-prepare-agent</id> + <goals> + <goal>prepare-agent</goal> + </goals> + </execution> + <execution> + <id>default-report</id> + <goals> + <goal>report</goal> + </goals> + </execution> + <execution> + <id>default-check</id> + <goals> + <goal>check</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <!-- More Project Information --> + <name>PDFtk Java</name> + <description>A port of pdftk into java</description> + <url>https://gitlab.com/pdftk-java/pdftk</url> +</project> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pdftk-v3.3.1/test/com/gitlab/pdftk_java/CryptoTest.java new/pdftk-v3.3.2/test/com/gitlab/pdftk_java/CryptoTest.java --- old/pdftk-v3.3.1/test/com/gitlab/pdftk_java/CryptoTest.java 2021-08-23 21:40:44.000000000 +0200 +++ new/pdftk-v3.3.2/test/com/gitlab/pdftk_java/CryptoTest.java 2021-12-20 18:20:25.000000000 +0100 @@ -7,6 +7,11 @@ public class CryptoTest extends BlackBox { @Test + public void set_password() { + pdftk("test/files/blank.pdf", "output", "/dev/null", "owner_pw", "\"'**", "user_pw", "**\"'"); + } + + @Test public void idempotent_aes() throws IOException { byte[] expected = slurpBytes("test/files/blank.pdf"); String encrypted = tmpDirectory.getRoot().getPath()+"/encrypted.pdf"; @@ -39,5 +44,4 @@ pdftk_error(1, encrypted, "input_pw", "Tr0ub4dor&3", "output", "-"); assertThat(systemErr.getLog(), containsString("OWNER OR USER PASSWORD REQUIRED, but incorrect")); } - };
