Skip to content

Fix NPE in getCryptFilters() - #720

Merged
MaximPlusov merged 2 commits into
integrationfrom
encryption
Aug 10, 2026
Merged

Fix NPE in getCryptFilters()#720
MaximPlusov merged 2 commits into
integrationfrom
encryption

Conversation

@LonelyMidoriya

@LonelyMidoriya LonelyMidoriya commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • Improved encrypted-document handling during document loading.
    • Invalid passwords now trigger the appropriate error and safely close related resources.
    • Prevented errors when accessing document objects before internal content is available.
  • Reliability
    • Document initialization now reports decryption and input/output failures more consistently.

@LonelyMidoriya LonelyMidoriya self-assigned this Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@LonelyMidoriya, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 14 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1495b7aa-f186-46e5-829d-b38d4013f654

📥 Commits

Reviewing files that changed from the base of the PR and between 706651e and 975a38a.

📒 Files selected for processing (3)
  • src/main/java/org/verapdf/cos/COSDocument.java
  • src/main/java/org/verapdf/io/IReader.java
  • src/main/java/org/verapdf/io/Reader.java
📝 Walkthrough

Walkthrough

The reader now exposes explicit decryption. COS document initialization decrypts the reader before loading structures and propagates IOException. Cached object access handles a null document body.

Changes

Explicit reader decryption

Layer / File(s) Summary
Reader decryption contract
src/main/java/org/verapdf/io/IReader.java, src/main/java/org/verapdf/io/Reader.java
IReader declares decrypt(). Reader validates encrypted-document passwords and closes the PDF source and resource handler before throwing InvalidPasswordException on failure.
COS document initialization
src/main/java/org/verapdf/cos/COSDocument.java
initCOSDocument decrypts the reader before loading structures and propagates IOException. getObject(COSKey) avoids dereferencing a null body.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant COSDocument
  participant Reader
  participant PDFSource
  participant ResourceHandler
  COSDocument->>Reader: decrypt()
  Reader->>Reader: validate encrypted-document password
  alt decryption fails
    Reader->>PDFSource: close
    Reader->>ResourceHandler: close
    Reader-->>COSDocument: InvalidPasswordException
  else decryption succeeds
    Reader-->>COSDocument: return
    COSDocument->>COSDocument: load document structures
  end
Loading

Suggested reviewers: maximplusov

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and identifies the reported null-pointer fix targeted by the changes, including the affected getCryptFilters() behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch encryption

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/org/verapdf/pd/encryption/PDEncryption.java`:
- Around line 188-190: Update the Reader resolution in PDEncryption(COSObject)
so it does not dereference a null result from StaticResources.getReader();
preferably pass the document Reader explicitly, or validate the missing Reader
before calling getObject and handle it through the existing error path.
- Around line 186-193: Update the indirect-filter handling in PDEncryption so
reader.getObject uses filter.getObjectKey() rather than the encryption
dictionary object key and offset overload; retain the resulting object for
PDCryptFilter construction. In the IOException log, report filter.getObjectKey()
and include the caught exception details.

In `@src/main/java/org/verapdf/tools/StaticResources.java`:
- Line 61: Scope the thread-local Reader lifecycle: in
src/main/java/org/verapdf/tools/StaticResources.java#L61-L61, update
StaticResources.clear() to call reader.remove(); in
src/main/java/org/verapdf/io/Reader.java#L60-L68, make init() restore the
previous Reader if initialization fails and make close() remove the slot only
when it still references this Reader.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a47b0ef-8dd5-4d7c-96c2-1d25c3dc082b

📥 Commits

Reviewing files that changed from the base of the PR and between d56121e and 06664fd.

📒 Files selected for processing (3)
  • src/main/java/org/verapdf/io/Reader.java
  • src/main/java/org/verapdf/pd/encryption/PDEncryption.java
  • src/main/java/org/verapdf/tools/StaticResources.java

Comment thread src/main/java/org/verapdf/pd/encryption/PDEncryption.java Outdated
Comment thread src/main/java/org/verapdf/pd/encryption/PDEncryption.java Outdated
Comment thread src/main/java/org/verapdf/tools/StaticResources.java Outdated
@LonelyMidoriya
LonelyMidoriya force-pushed the encryption branch 2 times, most recently from d46f996 to 706651e Compare August 10, 2026 13:43

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/org/verapdf/cos/COSDocument.java`:
- Around line 225-230: Update the object retrieval flow around the body cache
and this.reader.getObject(key) so that when this.body is null, a non-null newObj
is returned directly without calling this.body.set(...). Preserve caching
through this.body.set(...) when the body exists.

In `@src/main/java/org/verapdf/io/Reader.java`:
- Around line 145-158: Update Reader.decrypt so both getPDFSource().close() and
the document resource handler’s close() are attempted independently when
decryption is rejected. Capture any IOException from cleanup, attach it as a
suppressed exception to the intended InvalidPasswordException, and throw that
password exception after all cleanup has been attempted.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 17b39154-dc0c-492a-8331-6f983e78509b

📥 Commits

Reviewing files that changed from the base of the PR and between 06664fd and 706651e.

📒 Files selected for processing (3)
  • src/main/java/org/verapdf/cos/COSDocument.java
  • src/main/java/org/verapdf/io/IReader.java
  • src/main/java/org/verapdf/io/Reader.java

Comment thread src/main/java/org/verapdf/cos/COSDocument.java Outdated
Comment thread src/main/java/org/verapdf/io/Reader.java
@MaximPlusov
MaximPlusov merged commit 461c62a into integration Aug 10, 2026
9 checks passed
@MaximPlusov
MaximPlusov deleted the encryption branch August 11, 2026 11:38
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.

2 participants