Skip to content

Merge 2.2 and 2.4 in 3.0 - #1817

Merged
andreasrosdalw merged 16 commits into
3.0-java21from
merge-2.2-2.4-in-3.0
Dec 4, 2026
Merged

andreasrosdalw merged 16 commits into
3.0-java21from
merge-2.2-2.4-in-3.0

Conversation

@asturio

@asturio asturio commented Dec 4, 2026

Copy link
Copy Markdown
Member

Just a Merge so we can get rid of the merged branches.

asturio and others added 14 commits March 9, 2026 10:45
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
…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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
…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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
- Update bouncycastle, assertj and fop
- Update central-publishing-maven-plugin
- createRelease.sh from preview release-branch
- Update org.verapdf:validation-model 1.28.1 -> 1.30.4
- Only one mockito version used: 5.25.0 (upgraded)
- 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
… merge-2.2-2.4-in-3.0

# Conflicts:
#	README.md
#	openpdf-core/pom.xml
#	openpdf-core/src/main/java/org/openpdf/text/pdf/PdfNumber.java
#	openpdf-core/src/test/java/org/openpdf/text/FontFactoryImpTest.java
#	openpdf-core/src/test/java/org/openpdf/text/pdf/PdfNumberTest.java
#	openpdf-core/src/test/java/org/openpdf/text/pdf/encryption/DecryptUnsignedPermissionsTest.java
#	openpdf-fonts-extra/pom.xml
#	openpdf-html/pom.xml
#	openpdf-kotlin/pom.xml
#	openpdf-renderer/pom.xml
#	pdf-swing/pom.xml
#	pdf-toolbox/pom.xml
#	pom.xml
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

…2.2-2.4-in-3.0

# Conflicts:
#	openpdf-core-legacy/pom.xml
#	openpdf-core-legacy/src/main/java/com/lowagie/text/FontFactoryImp.java
#	openpdf-core-legacy/src/main/java/com/lowagie/text/pdf/PdfNumber.java
#	openpdf-core/pom.xml
#	openpdf-core/src/main/java/org/openpdf/text/FontFactoryImp.java
#	openpdf-core/src/main/java/org/openpdf/text/pdf/PdfNumber.java
#	openpdf-fonts-extra/pom.xml
#	openpdf-html/pom.xml
#	openpdf-kotlin/pom.xml
#	openpdf-renderer/pom.xml
#	pdf-swing/pom.xml
#	pdf-toolbox/pom.xml
#	pom.xml
@asturio
asturio force-pushed the merge-2.2-2.4-in-3.0 branch from a81dd34 to 321b0f9 Compare December 4, 2026 16:06
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

@andreasrosdalw
andreasrosdalw merged commit 51b2c8d into 3.0-java21 Dec 4, 2026
2 of 21 checks passed
@andreasrosdalw
andreasrosdalw deleted the merge-2.2-2.4-in-3.0 branch December 4, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants