From 44d83c2d9a85948b588851b86d549261bf763ec9 Mon Sep 17 00:00:00 2001 From: Claudio Clemens Date: Mon, 9 Mar 2026 10:45:28 +0100 Subject: [PATCH 01/14] Set version to 2.2.5 --- README.md | 6 +++--- createRelease.sh | 13 +++---------- openpdf-fonts-extra/pom.xml | 2 +- openpdf-html/pom.xml | 2 +- openpdf-kotlin/pom.xml | 2 +- openpdf-renderer/pom.xml | 2 +- openpdf/pom.xml | 2 +- pdf-swing/pom.xml | 2 +- pdf-toolbox/pom.xml | 2 +- pom.xml | 2 +- 10 files changed, 14 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index b22904c10..f28a6a7dd 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ and bugreports to this GitHub repository. ![Java 24](https://img.shields.io/badge/Java-24-blue?logo=java&logoColor=yellow) [![Kotlin](https://img.shields.io/badge/Kotlin-Supported-7F52FF?logo=kotlin&logoColor=white)](https://github.com/LibrePDF/OpenPDF/tree/master/openpdf-kotlin) -## OpenPDF version 2.2.4 released 2025-07-01 +## OpenPDF version 2.2.5 released 2026-03-09 -Get version 2.2.4 here: https://github.com/LibrePDF/OpenPDF/releases/tag/2.2.4 +Get version 2.2.5 here: https://github.com/LibrePDF/OpenPDF/releases/tag/2.2.5 ### Other versions @@ -56,7 +56,7 @@ Add this to your pom.xml file to use the latest version of OpenPDF: com.github.librepdf openpdf - 2.2.4 + 2.2.5 ``` diff --git a/createRelease.sh b/createRelease.sh index c65bda605..551410421 100755 --- a/createRelease.sh +++ b/createRelease.sh @@ -49,8 +49,8 @@ RC=$? if [ $RC -eq 0 ] then cat << EOD - Staging Release seems to be created. Please review it at https://oss.sonatype.org/#stagingRepositories - if everything seems fine, hit ENTER. Else break this script with Ctrl-C. + Staging Release seems to be created. Please review it at https://central.sonatype.com/publishing + if everything seems fine, publish from there. Else break this script with Ctrl-C. EOD read pause else @@ -59,14 +59,7 @@ else exit fi -echo "#5. Deploy release." -# Workaround for https://issues.sonatype.org/browse/OSSRH-66257 -export MAVEN_OPTS=" ---add-opens=java.base/java.util=ALL-UNNAMED ---add-opens=java.base/java.lang.reflect=ALL-UNNAMED ---add-opens=java.base/java.text=ALL-UNNAMED ---add-opens=java.desktop/java.awt.font=ALL-UNNAMED" -mvn nexus-staging:release +echo "#5. Deploy release. is deprecated. Should be rewritten" echo "#6. Finishing." echo " - set next SNAPSHOT to $NEW_VERSION" diff --git a/openpdf-fonts-extra/pom.xml b/openpdf-fonts-extra/pom.xml index ba206f6a4..ef159bb47 100644 --- a/openpdf-fonts-extra/pom.xml +++ b/openpdf-fonts-extra/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.2.5-SNAPSHOT + 2.2.5 openpdf-fonts-extra diff --git a/openpdf-html/pom.xml b/openpdf-html/pom.xml index 8197020cd..4d7e69f31 100644 --- a/openpdf-html/pom.xml +++ b/openpdf-html/pom.xml @@ -7,7 +7,7 @@ com.github.librepdf openpdf-parent - 2.2.5-SNAPSHOT + 2.2.5 openpdf-html diff --git a/openpdf-kotlin/pom.xml b/openpdf-kotlin/pom.xml index 659a9a999..4ace6e29c 100644 --- a/openpdf-kotlin/pom.xml +++ b/openpdf-kotlin/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.5-SNAPSHOT + 2.2.5 openpdf-kotlin diff --git a/openpdf-renderer/pom.xml b/openpdf-renderer/pom.xml index 83e6b38e3..b9905aeb5 100644 --- a/openpdf-renderer/pom.xml +++ b/openpdf-renderer/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.2.5-SNAPSHOT + 2.2.5 openpdf-renderer diff --git a/openpdf/pom.xml b/openpdf/pom.xml index edf4a5523..bdf937d36 100644 --- a/openpdf/pom.xml +++ b/openpdf/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.5-SNAPSHOT + 2.2.5 openpdf diff --git a/pdf-swing/pom.xml b/pdf-swing/pom.xml index 761746925..187056b47 100644 --- a/pdf-swing/pom.xml +++ b/pdf-swing/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.5-SNAPSHOT + 2.2.5 pdf-swing diff --git a/pdf-toolbox/pom.xml b/pdf-toolbox/pom.xml index 06ba55a8a..f80150b2e 100644 --- a/pdf-toolbox/pom.xml +++ b/pdf-toolbox/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.5-SNAPSHOT + 2.2.5 pdf-toolbox diff --git a/pom.xml b/pom.xml index 3c0e95791..f733a07c5 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.2.5-SNAPSHOT + 2.2.5 pom From ee06dad1d7f811e6a1a9d9ad4efd35375cd0e3cb Mon Sep 17 00:00:00 2001 From: Claudio Clemens Date: Mon, 9 Mar 2026 10:47:09 +0100 Subject: [PATCH 02/14] Set new Snapshot to 2.2.6-SNAPSHOT --- openpdf-fonts-extra/pom.xml | 2 +- openpdf-html/pom.xml | 2 +- openpdf-kotlin/pom.xml | 2 +- openpdf-renderer/pom.xml | 2 +- openpdf/pom.xml | 2 +- pdf-swing/pom.xml | 2 +- pdf-toolbox/pom.xml | 2 +- pom.xml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/openpdf-fonts-extra/pom.xml b/openpdf-fonts-extra/pom.xml index ef159bb47..c3861c643 100644 --- a/openpdf-fonts-extra/pom.xml +++ b/openpdf-fonts-extra/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.2.5 + 2.2.6-SNAPSHOT openpdf-fonts-extra diff --git a/openpdf-html/pom.xml b/openpdf-html/pom.xml index 4d7e69f31..7ed38a8b4 100644 --- a/openpdf-html/pom.xml +++ b/openpdf-html/pom.xml @@ -7,7 +7,7 @@ com.github.librepdf openpdf-parent - 2.2.5 + 2.2.6-SNAPSHOT openpdf-html diff --git a/openpdf-kotlin/pom.xml b/openpdf-kotlin/pom.xml index 4ace6e29c..fd1b843ac 100644 --- a/openpdf-kotlin/pom.xml +++ b/openpdf-kotlin/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.5 + 2.2.6-SNAPSHOT openpdf-kotlin diff --git a/openpdf-renderer/pom.xml b/openpdf-renderer/pom.xml index b9905aeb5..13d08229f 100644 --- a/openpdf-renderer/pom.xml +++ b/openpdf-renderer/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.2.5 + 2.2.6-SNAPSHOT openpdf-renderer diff --git a/openpdf/pom.xml b/openpdf/pom.xml index bdf937d36..e6798f3ca 100644 --- a/openpdf/pom.xml +++ b/openpdf/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.5 + 2.2.6-SNAPSHOT openpdf diff --git a/pdf-swing/pom.xml b/pdf-swing/pom.xml index 187056b47..1dcb1b68c 100644 --- a/pdf-swing/pom.xml +++ b/pdf-swing/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.5 + 2.2.6-SNAPSHOT pdf-swing diff --git a/pdf-toolbox/pom.xml b/pdf-toolbox/pom.xml index f80150b2e..9d00f8dab 100644 --- a/pdf-toolbox/pom.xml +++ b/pdf-toolbox/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.5 + 2.2.6-SNAPSHOT pdf-toolbox diff --git a/pom.xml b/pom.xml index f733a07c5..22efb7802 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.2.5 + 2.2.6-SNAPSHOT pom From 7609f68a2aea63f5a928c24267b46883abb5be12 Mon Sep 17 00:00:00 2001 From: Diego Garcia Date: Mon, 22 Jun 2026 22:04:18 -0300 Subject: [PATCH 03/14] fix: prevent duplicate font family entries in FontFactoryImp Guard the registerFamily insertion path with a contains check so that calling registerFamily with the same familyName/fullName pair more than once does not grow the family list unboundedly and slow down font lookup. Add a package-private getRegisteredFamily accessor and a unit test to cover the deduplication invariant. Co-Authored-By: Claude Sonnet 4.6 --- .../java/com/lowagie/text/FontFactoryImp.java | 24 ++++++++++++++- .../com/lowagie/text/FontFactoryImpTest.java | 29 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 openpdf/src/test/java/com/lowagie/text/FontFactoryImpTest.java diff --git a/openpdf/src/main/java/com/lowagie/text/FontFactoryImp.java b/openpdf/src/main/java/com/lowagie/text/FontFactoryImp.java index bc2566aa4..e90eb4bce 100644 --- a/openpdf/src/main/java/com/lowagie/text/FontFactoryImp.java +++ b/openpdf/src/main/java/com/lowagie/text/FontFactoryImp.java @@ -55,6 +55,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.List; @@ -515,7 +516,7 @@ public void registerFamily(String familyName, String fullName, String path) { tmp = new ArrayList<>(); tmp.add(fullName); fontFamilies.put(familyName, tmp); - } else { + } else if (!tmp.contains(fullName)) { int fullNameLength = fullName.length(); boolean inserted = false; for (int j = 0; j < tmp.size(); ++j) { @@ -727,6 +728,27 @@ public Set getRegisteredFamilies() { return Utilities.getKeySet(fontFamilies); } + /** + * Gets the font names registered for a given font family. Package-private: intended for + * testing the deduplication done by {@link #registerFamily}, not part of the public API. + * + * @param family the font family (case-insensitive) + * @return an unmodifiable copy of the registered font names for the family, or an empty list if + * the family is not registered + */ + List getRegisteredFamily(String family) { + lock.readLock().lock(); + try { + List members = fontFamilies.get(family.toLowerCase(Locale.ROOT)); + if (members == null) { + return Collections.emptyList(); + } + return Collections.unmodifiableList(new ArrayList<>(members)); + } finally { + lock.readLock().unlock(); + } + } + /** * Checks if a certain font is registered. * diff --git a/openpdf/src/test/java/com/lowagie/text/FontFactoryImpTest.java b/openpdf/src/test/java/com/lowagie/text/FontFactoryImpTest.java new file mode 100644 index 000000000..50f0a97bf --- /dev/null +++ b/openpdf/src/test/java/com/lowagie/text/FontFactoryImpTest.java @@ -0,0 +1,29 @@ +package com.lowagie.text; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class FontFactoryImpTest { + + /** + * Registering the same family/name combination several times must not add duplicate + * entries to the font family list, otherwise the list grows unbounded and slows down + * the lookup loop in {@link FontFactoryImp#getFont}. + */ + @Test + void registerFamilyShouldNotStoreDuplicateFullNames() { + FontFactoryImp fontFactory = new FontFactoryImp(); + + fontFactory.registerFamily("my-family", "My-Font-Regular", null); + fontFactory.registerFamily("my-family", "My-Font-Regular", null); + fontFactory.registerFamily("my-family", "My-Font-Regular", null); + + // A distinct member of the same family must still be added. + fontFactory.registerFamily("my-family", "My-Font-Bold", null); + + assertThat(fontFactory.getRegisteredFamilies()).contains("my-family"); + assertThat(fontFactory.getRegisteredFamily("my-family")) + .containsExactlyInAnyOrder("My-Font-Regular", "My-Font-Bold"); + } +} From 87aab569dfc581d3a2c6216dc12de0c318c700c2 Mon Sep 17 00:00:00 2001 From: Diego Garcia Date: Mon, 22 Jun 2026 22:04:18 -0300 Subject: [PATCH 04/14] fix: prevent duplicate font family entries in FontFactoryImp Guard the registerFamily insertion path with a contains check so that calling registerFamily with the same familyName/fullName pair more than once does not grow the family list unboundedly and slow down font lookup. Apply the fix and add a unit test to both openpdf-core-legacy and openpdf-core-modern modules, covering the deduplication invariant via a package-private getRegisteredFamily accessor. Co-Authored-By: Claude Sonnet 4.6 --- .../java/com/lowagie/text/FontFactoryImp.java | 24 ++++++++++++++- .../com/lowagie/text/FontFactoryImpTest.java | 29 +++++++++++++++++++ .../java/org/openpdf/text/FontFactoryImp.java | 24 ++++++++++++++- .../org/openpdf/text/FontFactoryImpTest.java | 29 +++++++++++++++++++ 4 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 openpdf-core-legacy/src/test/java/com/lowagie/text/FontFactoryImpTest.java create mode 100644 openpdf-core-modern/src/test/java/org/openpdf/text/FontFactoryImpTest.java diff --git a/openpdf-core-legacy/src/main/java/com/lowagie/text/FontFactoryImp.java b/openpdf-core-legacy/src/main/java/com/lowagie/text/FontFactoryImp.java index d1a815f7c..e06d6ab88 100644 --- a/openpdf-core-legacy/src/main/java/com/lowagie/text/FontFactoryImp.java +++ b/openpdf-core-legacy/src/main/java/com/lowagie/text/FontFactoryImp.java @@ -55,6 +55,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.List; @@ -517,7 +518,7 @@ public void registerFamily(String familyName, String fullName, String path) { tmp = new ArrayList<>(); tmp.add(fullName); fontFamilies.put(familyName, tmp); - } else { + } else if (!tmp.contains(fullName)) { int fullNameLength = fullName.length(); boolean inserted = false; for (int j = 0; j < tmp.size(); ++j) { @@ -729,6 +730,27 @@ public Set getRegisteredFamilies() { return Utilities.getKeySet(fontFamilies); } + /** + * Gets the font names registered for a given font family. Package-private: intended for + * testing the deduplication done by {@link #registerFamily}, not part of the public API. + * + * @param family the font family (case-insensitive) + * @return an unmodifiable copy of the registered font names for the family, or an empty list if + * the family is not registered + */ + List getRegisteredFamily(String family) { + lock.readLock().lock(); + try { + List members = fontFamilies.get(family.toLowerCase(Locale.ROOT)); + if (members == null) { + return Collections.emptyList(); + } + return Collections.unmodifiableList(new ArrayList<>(members)); + } finally { + lock.readLock().unlock(); + } + } + /** * Checks if a certain font is registered. * diff --git a/openpdf-core-legacy/src/test/java/com/lowagie/text/FontFactoryImpTest.java b/openpdf-core-legacy/src/test/java/com/lowagie/text/FontFactoryImpTest.java new file mode 100644 index 000000000..50f0a97bf --- /dev/null +++ b/openpdf-core-legacy/src/test/java/com/lowagie/text/FontFactoryImpTest.java @@ -0,0 +1,29 @@ +package com.lowagie.text; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class FontFactoryImpTest { + + /** + * Registering the same family/name combination several times must not add duplicate + * entries to the font family list, otherwise the list grows unbounded and slows down + * the lookup loop in {@link FontFactoryImp#getFont}. + */ + @Test + void registerFamilyShouldNotStoreDuplicateFullNames() { + FontFactoryImp fontFactory = new FontFactoryImp(); + + fontFactory.registerFamily("my-family", "My-Font-Regular", null); + fontFactory.registerFamily("my-family", "My-Font-Regular", null); + fontFactory.registerFamily("my-family", "My-Font-Regular", null); + + // A distinct member of the same family must still be added. + fontFactory.registerFamily("my-family", "My-Font-Bold", null); + + assertThat(fontFactory.getRegisteredFamilies()).contains("my-family"); + assertThat(fontFactory.getRegisteredFamily("my-family")) + .containsExactlyInAnyOrder("My-Font-Regular", "My-Font-Bold"); + } +} diff --git a/openpdf-core-modern/src/main/java/org/openpdf/text/FontFactoryImp.java b/openpdf-core-modern/src/main/java/org/openpdf/text/FontFactoryImp.java index e58bcb286..fb5031be2 100644 --- a/openpdf-core-modern/src/main/java/org/openpdf/text/FontFactoryImp.java +++ b/openpdf-core-modern/src/main/java/org/openpdf/text/FontFactoryImp.java @@ -55,6 +55,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.List; @@ -515,7 +516,7 @@ public void registerFamily(String familyName, String fullName, String path) { tmp = new ArrayList<>(); tmp.add(fullName); fontFamilies.put(familyName, tmp); - } else { + } else if (!tmp.contains(fullName)) { int fullNameLength = fullName.length(); boolean inserted = false; for (int j = 0; j < tmp.size(); ++j) { @@ -727,6 +728,27 @@ public Set getRegisteredFamilies() { return Utilities.getKeySet(fontFamilies); } + /** + * Gets the font names registered for a given font family. Package-private: intended for + * testing the deduplication done by {@link #registerFamily}, not part of the public API. + * + * @param family the font family (case-insensitive) + * @return an unmodifiable copy of the registered font names for the family, or an empty list if + * the family is not registered + */ + List getRegisteredFamily(String family) { + lock.readLock().lock(); + try { + List members = fontFamilies.get(family.toLowerCase(Locale.ROOT)); + if (members == null) { + return Collections.emptyList(); + } + return Collections.unmodifiableList(new ArrayList<>(members)); + } finally { + lock.readLock().unlock(); + } + } + /** * Checks if a certain font is registered. * diff --git a/openpdf-core-modern/src/test/java/org/openpdf/text/FontFactoryImpTest.java b/openpdf-core-modern/src/test/java/org/openpdf/text/FontFactoryImpTest.java new file mode 100644 index 000000000..d3dcea368 --- /dev/null +++ b/openpdf-core-modern/src/test/java/org/openpdf/text/FontFactoryImpTest.java @@ -0,0 +1,29 @@ +package org.openpdf.text; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class FontFactoryImpTest { + + /** + * Registering the same family/name combination several times must not add duplicate + * entries to the font family list, otherwise the list grows unbounded and slows down + * the lookup loop in {@link FontFactoryImp#getFont}. + */ + @Test + void registerFamilyShouldNotStoreDuplicateFullNames() { + FontFactoryImp fontFactory = new FontFactoryImp(); + + fontFactory.registerFamily("my-family", "My-Font-Regular", null); + fontFactory.registerFamily("my-family", "My-Font-Regular", null); + fontFactory.registerFamily("my-family", "My-Font-Regular", null); + + // A distinct member of the same family must still be added. + fontFactory.registerFamily("my-family", "My-Font-Bold", null); + + assertThat(fontFactory.getRegisteredFamilies()).contains("my-family"); + assertThat(fontFactory.getRegisteredFamily("my-family")) + .containsExactlyInAnyOrder("My-Font-Regular", "My-Font-Bold"); + } +} From 33e49261b184456a59f6e45d68a4fbe051c11730 Mon Sep 17 00:00:00 2001 From: Diego Garcia <24670735+garcia-d@users.noreply.github.com> Date: Fri, 27 Nov 2026 10:18:33 -0300 Subject: [PATCH 05/14] fix: prevent /P permissions overflow from corrupting decryption key (#1630) * fix: prevent /P permissions overflow from corrupting decryption key PdfNumber#intValue() narrowed the underlying double with a plain (int) cast. Some PDF producers write the /Encrypt dictionary's /P (permissions) entry using its unsigned 32-bit decimal representation instead of the equivalent signed value (e.g. 4294965956 instead of -1340) - both encode the identical 4-byte value, and this is spec-legal. Java's narrowing double-to-int conversion saturates rather than wraps for an out-of-range value, so such a /P value was misread as Integer.MAX_VALUE instead of -1340. That corrupted the encryption key the standard security handler derives, so its own recomputed /U check failed for every password - including a correct, empty one - and PdfReader reported BadPasswordException for a document that was never actually password-protected. Route the cast through long first, which reproduces the expected low-order-32-bit truncation instead of clamping. Add PdfNumberTest covering the truncation directly, and DecryptUnsignedPermissionsTest, a PdfReader-level regression test using a crafted PDF whose /P is written this way with an empty user password. Co-Authored-By: Claude Sonnet 5 * test: use PdfReader.isOwnerPasswordUsed() instead of reflection DecryptUnsignedPermissionsTest reached PdfReader's private ownerPasswordUsed field via reflection (setAccessible), which Codacy flagged as a high-severity visibility-alteration issue, plus a medium issue for wrapping the reflection exceptions in a raw RuntimeException. PdfReader already exposes a public isOwnerPasswordUsed() getter that returns the same field, so the reflection is unnecessary. Calling it directly returns the identical value and removes both findings. Co-Authored-By: Claude Sonnet 5 --------- Co-authored-by: Claude Sonnet 5 --- .../java/com/lowagie/text/pdf/PdfNumber.java | 11 ++++- .../com/lowagie/text/pdf/PdfNumberTest.java | 31 ++++++++++++++ .../DecryptUnsignedPermissionsTest.java | 39 ++++++++++++++++++ .../empty-user-password-unsigned-p-value.pdf | Bin 0 -> 615 bytes 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 openpdf/src/test/java/com/lowagie/text/pdf/PdfNumberTest.java create mode 100644 openpdf/src/test/java/com/lowagie/text/pdf/encryption/DecryptUnsignedPermissionsTest.java create mode 100644 openpdf/src/test/resources/permissions/empty-user-password-unsigned-p-value.pdf diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfNumber.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfNumber.java index 6f8fd3fe7..a8f6340f8 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfNumber.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfNumber.java @@ -135,11 +135,20 @@ public PdfNumber(float value) { /** * Returns the primitive int value of this object. + *

+ * Some PDF producers write 32-bit values that are meant to be interpreted as a two's-complement + * signed integer (for example the {@code /P} entry of an encryption dictionary) using their + * equivalent unsigned decimal representation instead of the negative signed value, e.g. + * {@code 4294965956} instead of {@code -1340}. A plain {@code (int) value} narrowing cast on the + * underlying double would clamp such an out-of-range value to + * {@link Integer#MAX_VALUE} rather than wrapping it, silently corrupting values like that. Going + * through long first reproduces the C-style truncation to the low-order 32 bits that + * PDF producers/consumers expect. * * @return The value as int */ public int intValue() { - return (int) value; + return (int) (long) value; } /** diff --git a/openpdf/src/test/java/com/lowagie/text/pdf/PdfNumberTest.java b/openpdf/src/test/java/com/lowagie/text/pdf/PdfNumberTest.java new file mode 100644 index 000000000..ae145c62f --- /dev/null +++ b/openpdf/src/test/java/com/lowagie/text/pdf/PdfNumberTest.java @@ -0,0 +1,31 @@ +package com.lowagie.text.pdf; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class PdfNumberTest { + + /** + * Some PDF producers write the encryption dictionary's {@code /P} (permissions) entry using its + * equivalent unsigned 32-bit decimal representation instead of the negative signed value, e.g. + * {@code 4294965956} instead of {@code -1340}. {@link PdfNumber#intValue()} must truncate such a + * value to its low-order 32 bits rather than clamping it to {@link Integer#MAX_VALUE}, otherwise + * the permission bits used to derive the decryption key no longer match the value the producer + * used, and a document with an empty user password is wrongly reported as requiring a password. + */ + @Test + void intValueTruncatesOutOfRangeUnsignedRepresentationInsteadOfClamping() { + assertEquals(-1340, new PdfNumber("4294965956").intValue()); + assertEquals(-1, new PdfNumber("4294967295").intValue()); + assertEquals(Integer.MIN_VALUE, new PdfNumber(String.valueOf(1L << 31)).intValue()); + } + + @Test + void intValueRoundTripsValuesWithinIntRange() { + assertEquals(-1340, new PdfNumber("-1340").intValue()); + assertEquals(0, new PdfNumber("0").intValue()); + assertEquals(Integer.MAX_VALUE, new PdfNumber(String.valueOf(Integer.MAX_VALUE)).intValue()); + assertEquals(Integer.MIN_VALUE, new PdfNumber(String.valueOf(Integer.MIN_VALUE)).intValue()); + } +} diff --git a/openpdf/src/test/java/com/lowagie/text/pdf/encryption/DecryptUnsignedPermissionsTest.java b/openpdf/src/test/java/com/lowagie/text/pdf/encryption/DecryptUnsignedPermissionsTest.java new file mode 100644 index 000000000..909b970e1 --- /dev/null +++ b/openpdf/src/test/java/com/lowagie/text/pdf/encryption/DecryptUnsignedPermissionsTest.java @@ -0,0 +1,39 @@ +package com.lowagie.text.pdf.encryption; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.lowagie.text.pdf.PdfReader; +import java.io.IOException; +import java.io.InputStream; +import org.junit.jupiter.api.Test; + +/** + * Regression test for a document that has no user password but is nevertheless reported by + * {@link PdfReader} as requiring one, because its {@code /Encrypt} dictionary writes the {@code /P} + * (permissions) entry using the unsigned 32-bit decimal representation of a negative value (e.g. + * {@code 4294965956} instead of {@code -1340}) - a convention some PDF producers use. + *

+ * {@link com.lowagie.text.pdf.PdfNumber#intValue()} used a plain {@code (int)} narrowing cast on the + * underlying double, which clamps such an out-of-range value to + * {@link Integer#MAX_VALUE} instead of truncating it to its low-order 32 bits. The corrupted + * permission value then fed into the standard security handler's key derivation, producing a user key + * that did not match {@code /U}, so {@link PdfReader} threw a {@link com.lowagie.text.exceptions.BadPasswordException} + * even though the correct (empty) password was supplied. + */ +class DecryptUnsignedPermissionsTest { + + @Test + void opensWithEmptyPasswordDespiteUnsignedPermissionsValue() throws IOException { + try (InputStream resource = getClass() + .getResourceAsStream("/permissions/empty-user-password-unsigned-p-value.pdf")) { + PdfReader pdfReader = new PdfReader(resource); + assertTrue(pdfReader.isEncrypted(), "PdfReader fails to report test file to be encrypted."); + assertFalse(pdfReader.isOwnerPasswordUsed(), "PdfReader fails to report limited permissions."); + assertEquals(1, pdfReader.getNumberOfPages(), + "PdfReader fails to report the correct number of pages"); + pdfReader.close(); + } + } +} diff --git a/openpdf/src/test/resources/permissions/empty-user-password-unsigned-p-value.pdf b/openpdf/src/test/resources/permissions/empty-user-password-unsigned-p-value.pdf new file mode 100644 index 0000000000000000000000000000000000000000..d528d8b2cde6819094b8d57ad8d805bd24145baa GIT binary patch literal 615 zcmah`%Wm6147}?rc=0ja7xx7SIy8xaqAg-LX)i_&``|h%3@MORAnDh4WuQusOL^mP zhTw2EyPNHm_=JrB4rBb)w(Q~cnb>uh!)ZLST{zMiWF79ij)q(*&Cm@@lD z!*PBBAsxGeHl-x9Lsxk5!4?-%Fg`^}w%EiCI+L7LMJmCgM-SJ7#0g)uR!j_m-Y zM{nv0hV4PIAJ7U(i3ekiw?1)H6iw2}p>aGBuZOx=kTfA#?E(seoY&rzQUVv;b?hg| z)yvC7rKuhpz7`m*m4*Uun1{<0hBr*tPc8Kh6TF7@5i|8$|FC%q{fVZU>3#o)K(qZg z)?Aj5*zJ&}*XJ3Q=kD2;n?oy&@@O?tl$5Ox7b=1NCDK)g_Jcnt%_*BL< Ko6YUrw)qQ-l%xUx literal 0 HcmV?d00001 From f2cf0d5c03e35f3e7273be902926274e1913e2e3 Mon Sep 17 00:00:00 2001 From: Diego Garcia <24670735+garcia-d@users.noreply.github.com> Date: Fri, 27 Nov 2026 10:18:43 -0300 Subject: [PATCH 06/14] fix: prevent /P permissions overflow from corrupting decryption key (#1632) * fix: prevent /P permissions overflow from corrupting decryption key PdfNumber#intValue() narrowed the underlying double with a plain (int) cast. Some PDF producers write the /Encrypt dictionary's /P (permissions) entry using its unsigned 32-bit decimal representation instead of the equivalent signed value (e.g. 4294965956 instead of -1340) - both encode the identical 4-byte value, and this is spec-legal. Java's narrowing double-to-int conversion saturates rather than wraps for an out-of-range value, so such a /P value was misread as Integer.MAX_VALUE instead of -1340. That corrupted the encryption key the standard security handler derives, so its own recomputed /U check failed for every password - including a correct, empty one - and PdfReader reported BadPasswordException for a document that was never actually password-protected. Route the cast through long first, which reproduces the expected low-order-32-bit truncation instead of clamping. Applied identically to both the legacy (com.lowagie) and modern (org.openpdf) copies of PdfNumber, since this branch ships both. Add PdfNumberTest covering the truncation directly, and DecryptUnsignedPermissionsTest, a PdfReader-level regression test using a crafted PDF whose /P is written this way with an empty user password, to both modules. Co-Authored-By: Claude Sonnet 5 * test: use PdfReader.isOwnerPasswordUsed() instead of reflection DecryptUnsignedPermissionsTest reached PdfReader's private ownerPasswordUsed field via reflection (setAccessible), which Codacy flagged as a high-severity visibility-alteration issue, plus a medium issue for wrapping the reflection exceptions in a raw RuntimeException. PdfReader already exposes a public isOwnerPasswordUsed() getter that returns the same field, so the reflection is unnecessary. Calling it directly returns the identical value and removes both findings. Co-Authored-By: Claude Sonnet 5 --------- Co-authored-by: Claude Sonnet 5 --- .../java/com/lowagie/text/pdf/PdfNumber.java | 11 ++++- .../com/lowagie/text/pdf/PdfNumberTest.java | 31 ++++++++++++++ .../DecryptUnsignedPermissionsTest.java | 39 ++++++++++++++++++ .../empty-user-password-unsigned-p-value.pdf | Bin 0 -> 615 bytes .../java/org/openpdf/text/pdf/PdfNumber.java | 11 ++++- .../org/openpdf/text/pdf/PdfNumberTest.java | 31 ++++++++++++++ .../DecryptUnsignedPermissionsTest.java | 39 ++++++++++++++++++ .../empty-user-password-unsigned-p-value.pdf | Bin 0 -> 615 bytes 8 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 openpdf-core-legacy/src/test/java/com/lowagie/text/pdf/PdfNumberTest.java create mode 100644 openpdf-core-legacy/src/test/java/com/lowagie/text/pdf/encryption/DecryptUnsignedPermissionsTest.java create mode 100644 openpdf-core-legacy/src/test/resources/permissions/empty-user-password-unsigned-p-value.pdf create mode 100644 openpdf-core-modern/src/test/java/org/openpdf/text/pdf/PdfNumberTest.java create mode 100644 openpdf-core-modern/src/test/java/org/openpdf/text/pdf/encryption/DecryptUnsignedPermissionsTest.java create mode 100644 openpdf-core-modern/src/test/resources/permissions/empty-user-password-unsigned-p-value.pdf diff --git a/openpdf-core-legacy/src/main/java/com/lowagie/text/pdf/PdfNumber.java b/openpdf-core-legacy/src/main/java/com/lowagie/text/pdf/PdfNumber.java index 8a785484e..0d52a0d2f 100644 --- a/openpdf-core-legacy/src/main/java/com/lowagie/text/pdf/PdfNumber.java +++ b/openpdf-core-legacy/src/main/java/com/lowagie/text/pdf/PdfNumber.java @@ -137,11 +137,20 @@ public PdfNumber(float value) { /** * Returns the primitive int value of this object. + *

+ * Some PDF producers write 32-bit values that are meant to be interpreted as a two's-complement + * signed integer (for example the {@code /P} entry of an encryption dictionary) using their + * equivalent unsigned decimal representation instead of the negative signed value, e.g. + * {@code 4294965956} instead of {@code -1340}. A plain {@code (int) value} narrowing cast on the + * underlying double would clamp such an out-of-range value to + * {@link Integer#MAX_VALUE} rather than wrapping it, silently corrupting values like that. Going + * through long first reproduces the C-style truncation to the low-order 32 bits that + * PDF producers/consumers expect. * * @return The value as int */ public int intValue() { - return (int) value; + return (int) (long) value; } /** diff --git a/openpdf-core-legacy/src/test/java/com/lowagie/text/pdf/PdfNumberTest.java b/openpdf-core-legacy/src/test/java/com/lowagie/text/pdf/PdfNumberTest.java new file mode 100644 index 000000000..ae145c62f --- /dev/null +++ b/openpdf-core-legacy/src/test/java/com/lowagie/text/pdf/PdfNumberTest.java @@ -0,0 +1,31 @@ +package com.lowagie.text.pdf; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class PdfNumberTest { + + /** + * Some PDF producers write the encryption dictionary's {@code /P} (permissions) entry using its + * equivalent unsigned 32-bit decimal representation instead of the negative signed value, e.g. + * {@code 4294965956} instead of {@code -1340}. {@link PdfNumber#intValue()} must truncate such a + * value to its low-order 32 bits rather than clamping it to {@link Integer#MAX_VALUE}, otherwise + * the permission bits used to derive the decryption key no longer match the value the producer + * used, and a document with an empty user password is wrongly reported as requiring a password. + */ + @Test + void intValueTruncatesOutOfRangeUnsignedRepresentationInsteadOfClamping() { + assertEquals(-1340, new PdfNumber("4294965956").intValue()); + assertEquals(-1, new PdfNumber("4294967295").intValue()); + assertEquals(Integer.MIN_VALUE, new PdfNumber(String.valueOf(1L << 31)).intValue()); + } + + @Test + void intValueRoundTripsValuesWithinIntRange() { + assertEquals(-1340, new PdfNumber("-1340").intValue()); + assertEquals(0, new PdfNumber("0").intValue()); + assertEquals(Integer.MAX_VALUE, new PdfNumber(String.valueOf(Integer.MAX_VALUE)).intValue()); + assertEquals(Integer.MIN_VALUE, new PdfNumber(String.valueOf(Integer.MIN_VALUE)).intValue()); + } +} diff --git a/openpdf-core-legacy/src/test/java/com/lowagie/text/pdf/encryption/DecryptUnsignedPermissionsTest.java b/openpdf-core-legacy/src/test/java/com/lowagie/text/pdf/encryption/DecryptUnsignedPermissionsTest.java new file mode 100644 index 000000000..909b970e1 --- /dev/null +++ b/openpdf-core-legacy/src/test/java/com/lowagie/text/pdf/encryption/DecryptUnsignedPermissionsTest.java @@ -0,0 +1,39 @@ +package com.lowagie.text.pdf.encryption; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.lowagie.text.pdf.PdfReader; +import java.io.IOException; +import java.io.InputStream; +import org.junit.jupiter.api.Test; + +/** + * Regression test for a document that has no user password but is nevertheless reported by + * {@link PdfReader} as requiring one, because its {@code /Encrypt} dictionary writes the {@code /P} + * (permissions) entry using the unsigned 32-bit decimal representation of a negative value (e.g. + * {@code 4294965956} instead of {@code -1340}) - a convention some PDF producers use. + *

+ * {@link com.lowagie.text.pdf.PdfNumber#intValue()} used a plain {@code (int)} narrowing cast on the + * underlying double, which clamps such an out-of-range value to + * {@link Integer#MAX_VALUE} instead of truncating it to its low-order 32 bits. The corrupted + * permission value then fed into the standard security handler's key derivation, producing a user key + * that did not match {@code /U}, so {@link PdfReader} threw a {@link com.lowagie.text.exceptions.BadPasswordException} + * even though the correct (empty) password was supplied. + */ +class DecryptUnsignedPermissionsTest { + + @Test + void opensWithEmptyPasswordDespiteUnsignedPermissionsValue() throws IOException { + try (InputStream resource = getClass() + .getResourceAsStream("/permissions/empty-user-password-unsigned-p-value.pdf")) { + PdfReader pdfReader = new PdfReader(resource); + assertTrue(pdfReader.isEncrypted(), "PdfReader fails to report test file to be encrypted."); + assertFalse(pdfReader.isOwnerPasswordUsed(), "PdfReader fails to report limited permissions."); + assertEquals(1, pdfReader.getNumberOfPages(), + "PdfReader fails to report the correct number of pages"); + pdfReader.close(); + } + } +} diff --git a/openpdf-core-legacy/src/test/resources/permissions/empty-user-password-unsigned-p-value.pdf b/openpdf-core-legacy/src/test/resources/permissions/empty-user-password-unsigned-p-value.pdf new file mode 100644 index 0000000000000000000000000000000000000000..d528d8b2cde6819094b8d57ad8d805bd24145baa GIT binary patch literal 615 zcmah`%Wm6147}?rc=0ja7xx7SIy8xaqAg-LX)i_&``|h%3@MORAnDh4WuQusOL^mP zhTw2EyPNHm_=JrB4rBb)w(Q~cnb>uh!)ZLST{zMiWF79ij)q(*&Cm@@lD z!*PBBAsxGeHl-x9Lsxk5!4?-%Fg`^}w%EiCI+L7LMJmCgM-SJ7#0g)uR!j_m-Y zM{nv0hV4PIAJ7U(i3ekiw?1)H6iw2}p>aGBuZOx=kTfA#?E(seoY&rzQUVv;b?hg| z)yvC7rKuhpz7`m*m4*Uun1{<0hBr*tPc8Kh6TF7@5i|8$|FC%q{fVZU>3#o)K(qZg z)?Aj5*zJ&}*XJ3Q=kD2;n?oy&@@O?tl$5Ox7b=1NCDK)g_Jcnt%_*BL< Ko6YUrw)qQ-l%xUx literal 0 HcmV?d00001 diff --git a/openpdf-core-modern/src/main/java/org/openpdf/text/pdf/PdfNumber.java b/openpdf-core-modern/src/main/java/org/openpdf/text/pdf/PdfNumber.java index b87784f2a..03b446af6 100644 --- a/openpdf-core-modern/src/main/java/org/openpdf/text/pdf/PdfNumber.java +++ b/openpdf-core-modern/src/main/java/org/openpdf/text/pdf/PdfNumber.java @@ -135,11 +135,20 @@ public PdfNumber(float value) { /** * Returns the primitive int value of this object. + *

+ * Some PDF producers write 32-bit values that are meant to be interpreted as a two's-complement + * signed integer (for example the {@code /P} entry of an encryption dictionary) using their + * equivalent unsigned decimal representation instead of the negative signed value, e.g. + * {@code 4294965956} instead of {@code -1340}. A plain {@code (int) value} narrowing cast on the + * underlying double would clamp such an out-of-range value to + * {@link Integer#MAX_VALUE} rather than wrapping it, silently corrupting values like that. Going + * through long first reproduces the C-style truncation to the low-order 32 bits that + * PDF producers/consumers expect. * * @return The value as int */ public int intValue() { - return (int) value; + return (int) (long) value; } /** diff --git a/openpdf-core-modern/src/test/java/org/openpdf/text/pdf/PdfNumberTest.java b/openpdf-core-modern/src/test/java/org/openpdf/text/pdf/PdfNumberTest.java new file mode 100644 index 000000000..edc9e9f38 --- /dev/null +++ b/openpdf-core-modern/src/test/java/org/openpdf/text/pdf/PdfNumberTest.java @@ -0,0 +1,31 @@ +package org.openpdf.text.pdf; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class PdfNumberTest { + + /** + * Some PDF producers write the encryption dictionary's {@code /P} (permissions) entry using its + * equivalent unsigned 32-bit decimal representation instead of the negative signed value, e.g. + * {@code 4294965956} instead of {@code -1340}. {@link PdfNumber#intValue()} must truncate such a + * value to its low-order 32 bits rather than clamping it to {@link Integer#MAX_VALUE}, otherwise + * the permission bits used to derive the decryption key no longer match the value the producer + * used, and a document with an empty user password is wrongly reported as requiring a password. + */ + @Test + void intValueTruncatesOutOfRangeUnsignedRepresentationInsteadOfClamping() { + assertEquals(-1340, new PdfNumber("4294965956").intValue()); + assertEquals(-1, new PdfNumber("4294967295").intValue()); + assertEquals(Integer.MIN_VALUE, new PdfNumber(String.valueOf(1L << 31)).intValue()); + } + + @Test + void intValueRoundTripsValuesWithinIntRange() { + assertEquals(-1340, new PdfNumber("-1340").intValue()); + assertEquals(0, new PdfNumber("0").intValue()); + assertEquals(Integer.MAX_VALUE, new PdfNumber(String.valueOf(Integer.MAX_VALUE)).intValue()); + assertEquals(Integer.MIN_VALUE, new PdfNumber(String.valueOf(Integer.MIN_VALUE)).intValue()); + } +} diff --git a/openpdf-core-modern/src/test/java/org/openpdf/text/pdf/encryption/DecryptUnsignedPermissionsTest.java b/openpdf-core-modern/src/test/java/org/openpdf/text/pdf/encryption/DecryptUnsignedPermissionsTest.java new file mode 100644 index 000000000..a7fa3186b --- /dev/null +++ b/openpdf-core-modern/src/test/java/org/openpdf/text/pdf/encryption/DecryptUnsignedPermissionsTest.java @@ -0,0 +1,39 @@ +package org.openpdf.text.pdf.encryption; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.openpdf.text.pdf.PdfReader; +import java.io.IOException; +import java.io.InputStream; +import org.junit.jupiter.api.Test; + +/** + * Regression test for a document that has no user password but is nevertheless reported by + * {@link PdfReader} as requiring one, because its {@code /Encrypt} dictionary writes the {@code /P} + * (permissions) entry using the unsigned 32-bit decimal representation of a negative value (e.g. + * {@code 4294965956} instead of {@code -1340}) - a convention some PDF producers use. + *

+ * {@link org.openpdf.text.pdf.PdfNumber#intValue()} used a plain {@code (int)} narrowing cast on the + * underlying double, which clamps such an out-of-range value to + * {@link Integer#MAX_VALUE} instead of truncating it to its low-order 32 bits. The corrupted + * permission value then fed into the standard security handler's key derivation, producing a user key + * that did not match {@code /U}, so {@link PdfReader} threw a {@link org.openpdf.text.exceptions.BadPasswordException} + * even though the correct (empty) password was supplied. + */ +class DecryptUnsignedPermissionsTest { + + @Test + void opensWithEmptyPasswordDespiteUnsignedPermissionsValue() throws IOException { + try (InputStream resource = getClass() + .getResourceAsStream("/permissions/empty-user-password-unsigned-p-value.pdf")) { + PdfReader pdfReader = new PdfReader(resource); + assertTrue(pdfReader.isEncrypted(), "PdfReader fails to report test file to be encrypted."); + assertFalse(pdfReader.isOwnerPasswordUsed(), "PdfReader fails to report limited permissions."); + assertEquals(1, pdfReader.getNumberOfPages(), + "PdfReader fails to report the correct number of pages"); + pdfReader.close(); + } + } +} diff --git a/openpdf-core-modern/src/test/resources/permissions/empty-user-password-unsigned-p-value.pdf b/openpdf-core-modern/src/test/resources/permissions/empty-user-password-unsigned-p-value.pdf new file mode 100644 index 0000000000000000000000000000000000000000..d528d8b2cde6819094b8d57ad8d805bd24145baa GIT binary patch literal 615 zcmah`%Wm6147}?rc=0ja7xx7SIy8xaqAg-LX)i_&``|h%3@MORAnDh4WuQusOL^mP zhTw2EyPNHm_=JrB4rBb)w(Q~cnb>uh!)ZLST{zMiWF79ij)q(*&Cm@@lD z!*PBBAsxGeHl-x9Lsxk5!4?-%Fg`^}w%EiCI+L7LMJmCgM-SJ7#0g)uR!j_m-Y zM{nv0hV4PIAJ7U(i3ekiw?1)H6iw2}p>aGBuZOx=kTfA#?E(seoY&rzQUVv;b?hg| z)yvC7rKuhpz7`m*m4*Uun1{<0hBr*tPc8Kh6TF7@5i|8$|FC%q{fVZU>3#o)K(qZg z)?Aj5*zJ&}*XJ3Q=kD2;n?oy&@@O?tl$5Ox7b=1NCDK)g_Jcnt%_*BL< Ko6YUrw)qQ-l%xUx literal 0 HcmV?d00001 From 749b4e635bf03057e93055f91746dc2db142f480 Mon Sep 17 00:00:00 2001 From: Claudio Clemens Date: Sun, 29 Nov 2026 19:19:59 +0100 Subject: [PATCH 07/14] chore: Update dependencies and release-script - Update bouncycastle, assertj and fop - Update central-publishing-maven-plugin - createRelease.sh from preview release-branch --- createRelease.sh | 6 ++---- pom.xml | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/createRelease.sh b/createRelease.sh index 551410421..c170ac8be 100755 --- a/createRelease.sh +++ b/createRelease.sh @@ -50,7 +50,7 @@ if [ $RC -eq 0 ] then cat << EOD Staging Release seems to be created. Please review it at https://central.sonatype.com/publishing - if everything seems fine, publish from there. Else break this script with Ctrl-C. + if everything seems fine, publish it there and hit ENTER. Else break this script with Ctrl-C. EOD read pause else @@ -59,9 +59,7 @@ else exit fi -echo "#5. Deploy release. is deprecated. Should be rewritten" - -echo "#6. Finishing." +echo "#5. Finishing." echo " - set next SNAPSHOT to $NEW_VERSION" mvn versions:set -DnewVersion="$NEW_VERSION" echo " - commit changes" diff --git a/pom.xml b/pom.xml index 22efb7802..51f0b6dcf 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ UTF-8 - 0.8.0 + 0.12.0 6.0.0 3.6.0 3.5.0 @@ -84,10 +84,10 @@ 1.3.7 - 1.81 + 1.87 2.19.0 2.2.0 - 2.11 + 2.12 6.1.0 1.0.24 1.5.6 @@ -96,7 +96,7 @@ 2.0.17 - 3.27.3 + 3.27.7 10.26.1 0.8.13 5.13.3 From 844d04a44e43e591ffcf63fe5fbd387a68e19a7d Mon Sep 17 00:00:00 2001 From: Claudio Clemens Date: Mon, 30 Nov 2026 22:33:58 +0100 Subject: [PATCH 08/14] chore: Update dependencies - Update org.verapdf:validation-model 1.28.1 -> 1.30.4 - Only one mockito version used: 5.25.0 (upgraded) --- openpdf-html/pom.xml | 5 +++-- openpdf/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/openpdf-html/pom.xml b/openpdf-html/pom.xml index 7ed38a8b4..b2d5238a4 100644 --- a/openpdf-html/pom.xml +++ b/openpdf-html/pom.xml @@ -11,7 +11,9 @@ openpdf-html - openpdf-html is a CSS 2.1 renderer written in Java. This artifact contains the core rendering and layout code as well as Java2D output. + openpdf-html is a CSS 2.1 renderer written in Java. This artifact contains the core rendering and layout + code as well as Java2D output. + @@ -38,7 +40,6 @@ org.mockito mockito-core - 5.18.0 test diff --git a/openpdf/pom.xml b/openpdf/pom.xml index e6798f3ca..c314f2cf1 100644 --- a/openpdf/pom.xml +++ b/openpdf/pom.xml @@ -68,7 +68,7 @@ org.verapdf validation-model - 1.28.1 + 1.30.4 true test diff --git a/pom.xml b/pom.xml index 51f0b6dcf..a0da557d7 100644 --- a/pom.xml +++ b/pom.xml @@ -100,7 +100,7 @@ 10.26.1 0.8.13 5.13.3 - 5.17.0 + 5.25.0 From ee18d4ca8d32c4b66c9a479c75598b9aa04eec63 Mon Sep 17 00:00:00 2001 From: Claudio Clemens Date: Mon, 30 Nov 2026 22:35:02 +0100 Subject: [PATCH 09/14] Set version to 2.2.6 --- openpdf-fonts-extra/pom.xml | 2 +- openpdf-html/pom.xml | 2 +- openpdf-kotlin/pom.xml | 2 +- openpdf-renderer/pom.xml | 2 +- openpdf/pom.xml | 2 +- pdf-swing/pom.xml | 2 +- pdf-toolbox/pom.xml | 2 +- pom.xml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/openpdf-fonts-extra/pom.xml b/openpdf-fonts-extra/pom.xml index c3861c643..d355ddc86 100644 --- a/openpdf-fonts-extra/pom.xml +++ b/openpdf-fonts-extra/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.2.6-SNAPSHOT + 2.2.6 openpdf-fonts-extra diff --git a/openpdf-html/pom.xml b/openpdf-html/pom.xml index b2d5238a4..796f66a25 100644 --- a/openpdf-html/pom.xml +++ b/openpdf-html/pom.xml @@ -7,7 +7,7 @@ com.github.librepdf openpdf-parent - 2.2.6-SNAPSHOT + 2.2.6 openpdf-html diff --git a/openpdf-kotlin/pom.xml b/openpdf-kotlin/pom.xml index fd1b843ac..2b576302c 100644 --- a/openpdf-kotlin/pom.xml +++ b/openpdf-kotlin/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.6-SNAPSHOT + 2.2.6 openpdf-kotlin diff --git a/openpdf-renderer/pom.xml b/openpdf-renderer/pom.xml index 13d08229f..1ec4a098b 100644 --- a/openpdf-renderer/pom.xml +++ b/openpdf-renderer/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.2.6-SNAPSHOT + 2.2.6 openpdf-renderer diff --git a/openpdf/pom.xml b/openpdf/pom.xml index c314f2cf1..c30d18297 100644 --- a/openpdf/pom.xml +++ b/openpdf/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.6-SNAPSHOT + 2.2.6 openpdf diff --git a/pdf-swing/pom.xml b/pdf-swing/pom.xml index 1dcb1b68c..6c9a09933 100644 --- a/pdf-swing/pom.xml +++ b/pdf-swing/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.6-SNAPSHOT + 2.2.6 pdf-swing diff --git a/pdf-toolbox/pom.xml b/pdf-toolbox/pom.xml index 9d00f8dab..4a4b7145f 100644 --- a/pdf-toolbox/pom.xml +++ b/pdf-toolbox/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.6-SNAPSHOT + 2.2.6 pdf-toolbox diff --git a/pom.xml b/pom.xml index a0da557d7..acfd8ac0c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.2.6-SNAPSHOT + 2.2.6 pom From a88581c964186cabb122cabe99708932b167927e Mon Sep 17 00:00:00 2001 From: Claudio Clemens Date: Mon, 30 Nov 2026 22:36:49 +0100 Subject: [PATCH 10/14] Set new Snapshot to 2.2.7-SNAPSHOT --- openpdf-fonts-extra/pom.xml | 2 +- openpdf-html/pom.xml | 2 +- openpdf-kotlin/pom.xml | 2 +- openpdf-renderer/pom.xml | 2 +- openpdf/pom.xml | 2 +- pdf-swing/pom.xml | 2 +- pdf-toolbox/pom.xml | 2 +- pom.xml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/openpdf-fonts-extra/pom.xml b/openpdf-fonts-extra/pom.xml index d355ddc86..bfd3083c5 100644 --- a/openpdf-fonts-extra/pom.xml +++ b/openpdf-fonts-extra/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.2.6 + 2.2.7-SNAPSHOT openpdf-fonts-extra diff --git a/openpdf-html/pom.xml b/openpdf-html/pom.xml index 796f66a25..2f8e6d76a 100644 --- a/openpdf-html/pom.xml +++ b/openpdf-html/pom.xml @@ -7,7 +7,7 @@ com.github.librepdf openpdf-parent - 2.2.6 + 2.2.7-SNAPSHOT openpdf-html diff --git a/openpdf-kotlin/pom.xml b/openpdf-kotlin/pom.xml index 2b576302c..354ae11be 100644 --- a/openpdf-kotlin/pom.xml +++ b/openpdf-kotlin/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.6 + 2.2.7-SNAPSHOT openpdf-kotlin diff --git a/openpdf-renderer/pom.xml b/openpdf-renderer/pom.xml index 1ec4a098b..1736ec186 100644 --- a/openpdf-renderer/pom.xml +++ b/openpdf-renderer/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.2.6 + 2.2.7-SNAPSHOT openpdf-renderer diff --git a/openpdf/pom.xml b/openpdf/pom.xml index c30d18297..ca89bb0e1 100644 --- a/openpdf/pom.xml +++ b/openpdf/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.6 + 2.2.7-SNAPSHOT openpdf diff --git a/pdf-swing/pom.xml b/pdf-swing/pom.xml index 6c9a09933..20c566304 100644 --- a/pdf-swing/pom.xml +++ b/pdf-swing/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.6 + 2.2.7-SNAPSHOT pdf-swing diff --git a/pdf-toolbox/pom.xml b/pdf-toolbox/pom.xml index 4a4b7145f..f805666fa 100644 --- a/pdf-toolbox/pom.xml +++ b/pdf-toolbox/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.2.6 + 2.2.7-SNAPSHOT pdf-toolbox diff --git a/pom.xml b/pom.xml index acfd8ac0c..d893e2e03 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.2.6 + 2.2.7-SNAPSHOT pom From b04a14573f9a55e6f45a3331bfa5791c6d8b12a8 Mon Sep 17 00:00:00 2001 From: Claudio Clemens Date: Mon, 30 Nov 2026 22:50:22 +0100 Subject: [PATCH 11/14] feat: Update dependencies - createRelease.sh from preview release-branch - Update org.verapdf:validation-model 1.28.1 -> 1.30.4 - Update central-publishing-maven-plugin 0.8.0 -> 0.12.0 - Update bouncycastle 1.81 -> 1.87 - Update fop 2.11 -> 2.12 - Update assertj 3.27.4 -> 3.27.7 - Update mockito to only one version: 5.25.0 --- createRelease.sh | 15 +++------------ openpdf-core-legacy/pom.xml | 2 +- openpdf-core-modern/pom.xml | 2 +- openpdf-html/pom.xml | 5 +++-- pom.xml | 10 +++++----- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/createRelease.sh b/createRelease.sh index c65bda605..c170ac8be 100755 --- a/createRelease.sh +++ b/createRelease.sh @@ -49,8 +49,8 @@ RC=$? if [ $RC -eq 0 ] then cat << EOD - Staging Release seems to be created. Please review it at https://oss.sonatype.org/#stagingRepositories - if everything seems fine, hit ENTER. Else break this script with Ctrl-C. + Staging Release seems to be created. Please review it at https://central.sonatype.com/publishing + if everything seems fine, publish it there and hit ENTER. Else break this script with Ctrl-C. EOD read pause else @@ -59,16 +59,7 @@ else exit fi -echo "#5. Deploy release." -# Workaround for https://issues.sonatype.org/browse/OSSRH-66257 -export MAVEN_OPTS=" ---add-opens=java.base/java.util=ALL-UNNAMED ---add-opens=java.base/java.lang.reflect=ALL-UNNAMED ---add-opens=java.base/java.text=ALL-UNNAMED ---add-opens=java.desktop/java.awt.font=ALL-UNNAMED" -mvn nexus-staging:release - -echo "#6. Finishing." +echo "#5. Finishing." echo " - set next SNAPSHOT to $NEW_VERSION" mvn versions:set -DnewVersion="$NEW_VERSION" echo " - commit changes" diff --git a/openpdf-core-legacy/pom.xml b/openpdf-core-legacy/pom.xml index 4973d3800..7a6bb5f75 100644 --- a/openpdf-core-legacy/pom.xml +++ b/openpdf-core-legacy/pom.xml @@ -69,7 +69,7 @@ org.verapdf validation-model - 1.28.2 + 1.30.4 true test diff --git a/openpdf-core-modern/pom.xml b/openpdf-core-modern/pom.xml index 9af249182..1c698798e 100644 --- a/openpdf-core-modern/pom.xml +++ b/openpdf-core-modern/pom.xml @@ -69,7 +69,7 @@ org.verapdf validation-model - 1.28.2 + 1.30.4 true test diff --git a/openpdf-html/pom.xml b/openpdf-html/pom.xml index 785c59eb7..ae318aee9 100644 --- a/openpdf-html/pom.xml +++ b/openpdf-html/pom.xml @@ -11,7 +11,9 @@ openpdf-html - openpdf-html is a CSS 2.1 renderer written in Java. This artifact contains the core rendering and layout code as well as Java2D output. + openpdf-html is a CSS 2.1 renderer written in Java. This artifact contains the core rendering and layout + code as well as Java2D output. + @@ -38,7 +40,6 @@ org.mockito mockito-core - 5.18.0 test diff --git a/pom.xml b/pom.xml index b698f1cf7..c2f0ec139 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ UTF-8 - 0.8.0 + 0.12.0 6.0.0 3.6.0 3.5.0 @@ -85,10 +85,10 @@ 1.3.7 - 1.81 + 1.87 2.20.0 2.2.0 - 2.11 + 2.12 6.1.0 1.0.24 1.5.6 @@ -97,11 +97,11 @@ 2.0.17 - 3.27.4 + 3.27.7 11.0.0 0.8.13 5.13.4 - 5.17.0 + 5.25.0 From 4ea7a76369ad224fe17c91303a2e039d799408f1 Mon Sep 17 00:00:00 2001 From: Claudio Clemens Date: Mon, 30 Nov 2026 22:58:11 +0100 Subject: [PATCH 12/14] Set version to 2.4.1 --- openpdf-core-legacy/pom.xml | 2 +- openpdf-core-modern/pom.xml | 2 +- openpdf-fonts-extra/pom.xml | 2 +- openpdf-html/pom.xml | 2 +- openpdf-kotlin/pom.xml | 2 +- openpdf-renderer/pom.xml | 2 +- pdf-swing/pom.xml | 2 +- pdf-toolbox/pom.xml | 2 +- pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/openpdf-core-legacy/pom.xml b/openpdf-core-legacy/pom.xml index 7a6bb5f75..623c8a4f4 100644 --- a/openpdf-core-legacy/pom.xml +++ b/openpdf-core-legacy/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.4.1-SNAPSHOT + 2.4.1 openpdf diff --git a/openpdf-core-modern/pom.xml b/openpdf-core-modern/pom.xml index 1c698798e..07417dc56 100644 --- a/openpdf-core-modern/pom.xml +++ b/openpdf-core-modern/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.4.1-SNAPSHOT + 2.4.1 openpdf-core-modern diff --git a/openpdf-fonts-extra/pom.xml b/openpdf-fonts-extra/pom.xml index 55b29c7c6..a1a04f594 100644 --- a/openpdf-fonts-extra/pom.xml +++ b/openpdf-fonts-extra/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.4.1-SNAPSHOT + 2.4.1 openpdf-fonts-extra diff --git a/openpdf-html/pom.xml b/openpdf-html/pom.xml index ae318aee9..2d4a7ce4b 100644 --- a/openpdf-html/pom.xml +++ b/openpdf-html/pom.xml @@ -7,7 +7,7 @@ com.github.librepdf openpdf-parent - 2.4.1-SNAPSHOT + 2.4.1 openpdf-html diff --git a/openpdf-kotlin/pom.xml b/openpdf-kotlin/pom.xml index 184edc784..8f7392b6a 100644 --- a/openpdf-kotlin/pom.xml +++ b/openpdf-kotlin/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.4.1-SNAPSHOT + 2.4.1 openpdf-kotlin diff --git a/openpdf-renderer/pom.xml b/openpdf-renderer/pom.xml index b4ba91757..94232466f 100644 --- a/openpdf-renderer/pom.xml +++ b/openpdf-renderer/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.4.1-SNAPSHOT + 2.4.1 openpdf-renderer diff --git a/pdf-swing/pom.xml b/pdf-swing/pom.xml index 48f1a060a..710008d1b 100644 --- a/pdf-swing/pom.xml +++ b/pdf-swing/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.4.1-SNAPSHOT + 2.4.1 pdf-swing diff --git a/pdf-toolbox/pom.xml b/pdf-toolbox/pom.xml index f02bb52f9..11e58c86d 100644 --- a/pdf-toolbox/pom.xml +++ b/pdf-toolbox/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.4.1-SNAPSHOT + 2.4.1 pdf-toolbox diff --git a/pom.xml b/pom.xml index c2f0ec139..4b649708e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.4.1-SNAPSHOT + 2.4.1 pom From 53005e3b18eb82a62b3bcf66fa81752871ba20a3 Mon Sep 17 00:00:00 2001 From: Claudio Clemens Date: Mon, 30 Nov 2026 23:00:05 +0100 Subject: [PATCH 13/14] Set new Snapshot to 2.4.2-SNAPSHOT --- openpdf-core-legacy/pom.xml | 2 +- openpdf-core-modern/pom.xml | 2 +- openpdf-fonts-extra/pom.xml | 2 +- openpdf-html/pom.xml | 2 +- openpdf-kotlin/pom.xml | 2 +- openpdf-renderer/pom.xml | 2 +- pdf-swing/pom.xml | 2 +- pdf-toolbox/pom.xml | 2 +- pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/openpdf-core-legacy/pom.xml b/openpdf-core-legacy/pom.xml index 623c8a4f4..7780a8c2a 100644 --- a/openpdf-core-legacy/pom.xml +++ b/openpdf-core-legacy/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.4.1 + 2.4.2-SNAPSHOT openpdf diff --git a/openpdf-core-modern/pom.xml b/openpdf-core-modern/pom.xml index 07417dc56..1fa9e6aed 100644 --- a/openpdf-core-modern/pom.xml +++ b/openpdf-core-modern/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.4.1 + 2.4.2-SNAPSHOT openpdf-core-modern diff --git a/openpdf-fonts-extra/pom.xml b/openpdf-fonts-extra/pom.xml index a1a04f594..c42b69f6c 100644 --- a/openpdf-fonts-extra/pom.xml +++ b/openpdf-fonts-extra/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.4.1 + 2.4.2-SNAPSHOT openpdf-fonts-extra diff --git a/openpdf-html/pom.xml b/openpdf-html/pom.xml index 2d4a7ce4b..e4bf6d3e7 100644 --- a/openpdf-html/pom.xml +++ b/openpdf-html/pom.xml @@ -7,7 +7,7 @@ com.github.librepdf openpdf-parent - 2.4.1 + 2.4.2-SNAPSHOT openpdf-html diff --git a/openpdf-kotlin/pom.xml b/openpdf-kotlin/pom.xml index 8f7392b6a..81d3126bc 100644 --- a/openpdf-kotlin/pom.xml +++ b/openpdf-kotlin/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.4.1 + 2.4.2-SNAPSHOT openpdf-kotlin diff --git a/openpdf-renderer/pom.xml b/openpdf-renderer/pom.xml index 94232466f..0c95fe232 100644 --- a/openpdf-renderer/pom.xml +++ b/openpdf-renderer/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.4.1 + 2.4.2-SNAPSHOT openpdf-renderer diff --git a/pdf-swing/pom.xml b/pdf-swing/pom.xml index 710008d1b..24f279ba6 100644 --- a/pdf-swing/pom.xml +++ b/pdf-swing/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.4.1 + 2.4.2-SNAPSHOT pdf-swing diff --git a/pdf-toolbox/pom.xml b/pdf-toolbox/pom.xml index 11e58c86d..c9d4d2c69 100644 --- a/pdf-toolbox/pom.xml +++ b/pdf-toolbox/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 2.4.1 + 2.4.2-SNAPSHOT pdf-toolbox diff --git a/pom.xml b/pom.xml index 4b649708e..7ffc91abe 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.librepdf openpdf-parent - 2.4.1 + 2.4.2-SNAPSHOT pom From 932fb6f207a3c27e7c1dc73177a0cb58cb7eee45 Mon Sep 17 00:00:00 2001 From: Claudio Clemens Date: Fri, 4 Dec 2026 17:35:36 +0100 Subject: [PATCH 14/14] test: Add regression tests for permissions and font registration From other branches --- .../org/openpdf/text/FontFactoryImpTest.java | 29 ++++++++++++++ .../DecryptUnsignedPermissionsTest.java | 38 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 openpdf-core/src/test/java/org/openpdf/text/FontFactoryImpTest.java create mode 100644 openpdf-core/src/test/java/org/openpdf/text/pdf/encryption/DecryptUnsignedPermissionsTest.java diff --git a/openpdf-core/src/test/java/org/openpdf/text/FontFactoryImpTest.java b/openpdf-core/src/test/java/org/openpdf/text/FontFactoryImpTest.java new file mode 100644 index 000000000..c0d1e1783 --- /dev/null +++ b/openpdf-core/src/test/java/org/openpdf/text/FontFactoryImpTest.java @@ -0,0 +1,29 @@ +package org.openpdf.text; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class FontFactoryImpTest { + + /** + * Registering the same family/name combination several times must not add duplicate entries to the font family + * list, otherwise the list grows unbounded and slows down the lookup loop in {@link FontFactoryImp#getFont}. + */ + @Test + void registerFamilyShouldNotStoreDuplicateFullNames() { + FontFactoryImp fontFactory = new FontFactoryImp(); + + fontFactory.registerFamily("my-family", "My-Font-Regular", null); + fontFactory.registerFamily("my-family", "My-Font-Regular", null); + fontFactory.registerFamily("my-family", "My-Font-Regular", null); + + // A distinct member of the same family must still be added. + fontFactory.registerFamily("my-family", "My-Font-Bold", null); + + assertThat(fontFactory.getRegisteredFamilies()).contains("my-family"); + assertThat(fontFactory.getRegisteredFamily("my-family")) + .containsExactlyInAnyOrder("My-Font-Regular", "My-Font-Bold"); + } + +} \ No newline at end of file diff --git a/openpdf-core/src/test/java/org/openpdf/text/pdf/encryption/DecryptUnsignedPermissionsTest.java b/openpdf-core/src/test/java/org/openpdf/text/pdf/encryption/DecryptUnsignedPermissionsTest.java new file mode 100644 index 000000000..9e8d1aa60 --- /dev/null +++ b/openpdf-core/src/test/java/org/openpdf/text/pdf/encryption/DecryptUnsignedPermissionsTest.java @@ -0,0 +1,38 @@ +package org.openpdf.text.pdf.encryption; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.io.InputStream; +import org.junit.jupiter.api.Test; +import org.openpdf.text.pdf.PdfReader; + +/** + * Regression test for a document that has no user password but is nevertheless reported by {@link PdfReader} as + * requiring one, because its {@code /Encrypt} dictionary writes the {@code /P} (permissions) entry using the unsigned + * 32-bit decimal representation of a negative value (e.g. {@code 4294965956} instead of {@code -1340}) - a convention + * some PDF producers use. + *

+ * {@link org.openpdf.text.pdf.PdfNumber#intValue()} used a plain {@code (int)} narrowing cast on the underlying + * double, which clamps such an out-of-range value to {@link Integer#MAX_VALUE} instead of truncating it + * to its low-order 32 bits. The corrupted permission value then fed into the standard security handler's key + * derivation, producing a user key that did not match {@code /U}, so {@link PdfReader} threw a + * {@link org.openpdf.text.exceptions.BadPasswordException} even though the correct (empty) password was supplied. + */ +class DecryptUnsignedPermissionsTest { + + @Test + void opensWithEmptyPasswordDespiteUnsignedPermissionsValue() throws IOException { + try (InputStream resource = getClass() + .getResourceAsStream("/permissions/empty-user-password-unsigned-p-value.pdf")) { + PdfReader pdfReader = new PdfReader(resource); + assertTrue(pdfReader.isEncrypted(), "PdfReader fails to report test file to be encrypted."); + assertFalse(pdfReader.isOwnerPasswordUsed(), "PdfReader fails to report limited permissions."); + assertEquals(1, pdfReader.getNumberOfPages(), + "PdfReader fails to report the correct number of pages"); + pdfReader.close(); + } + } +}