Skip to content

Add real veraPDF ISO 19005 PDF/A conformance validation tests - #297

Merged
balazs-szucs merged 1 commit into
test/normalizer-conformance-testsfrom
test/verapdf-conformance-suite
Nov 18, 2026
Merged

balazs-szucs merged 1 commit into
test/normalizer-conformance-testsfrom
test/verapdf-conformance-suite

Conversation

@balazs-szucs

@balazs-szucs balazs-szucs commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Description of Changes

Adds PdfFontVeraPdfTest along with strict detection, compression, and PDF/X regression coverage validating repaired, normalized, and compressed PDFs against real veraPDF ISO 19005 (PDF/A-1b, PDF/A-2b, PDF/A-3b) profiles. Provides independent standards-grade verification that font subsetting, normalization, and PDF/X conversion emit spec-compliant documents.

Changed:

  • Add PdfFontVeraPdfTest.java exercising veraPDF 1.30.0 1b, 2b, and 3b validation on repaired and subsetted outputs.
  • Expand PdfCompressorDetectionTest.java, PdfCompressorTest.java, and PdfXConverterTest.java with ISO conformance and compression-gate assertions.
  • Add PdfRepairStructuralDamageTest.java, PdfRepairTest, PdfFontEmbedderTest, and FontNormalizerTest conformance regressions.
  • This PR is tests-only: production changes moved to PR Harden PDF/A and PDF/X conformance, memory safety, and Rust bounds checks #295 and earlier stack PRs.

Checklist

General

  • I have read the Contributing Guide
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Notable user-facing changes are recorded under ## [Unreleased] in CHANGELOG.md

Library changes

  • Javadoc covers any new or changed public type or member
  • Public API changes are additive, or .github/workflows/compatibility.yml excludes the break with a reason
  • Version references stay consistent across the README, docs/installation.md, and the POMs

Native or FFM changes

  • Rebuilt the bridge at the stack tip (bash native/build-real.sh)
  • Ran ./gradlew :jpdfium:integrationTest
  • Updated native/bridge/include/jpdfium.h and the ABI notes for any ABI change

Testing

  • Added or updated tests that cover the change
  • ./gradlew :jpdfium:integrationTest passes

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Summary

Summary by CodeRabbit

  • Bug Fixes
    • Repair leaves signed PDFs unchanged when they can be opened, helping preserve their signatures.
    • Repair handles more malformed or truncated PDFs and reports failure when usable pages cannot be recovered.
    • Font embedding and normalization better preserve inherited Unicode mappings, correct font widths, and valid character-to-glyph information.
    • Lossless compression better preserves PDF/A structure and metadata.
  • Tests
    • Expanded coverage for PDF repair, compression, font embedding and normalization, and PDF/A conformance.
    • Added checks for metadata detection, color-space conversion, page boxes, and disallowed content.

The pull request changes PDF repair, font normalization, and font embedding behavior. It also adds tests for PDF/A detection and conformance, PDF compression, PDF repair, and PDF/X conversion.

Changes: Font normalization and embedding

Layer / File(s) Summary
Normalize font programs and mappings
native/bridge/include/jpdfium_font_internal.h, native/bridge/src/jpdfium_font_normalizer.cpp, native/bridge/src/jpdfium_font_shared.cpp, native/bridge/src/jpdfium_qpdf_fonts_subset.cpp, jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
Normalization updates CID widths and CIDSet generation, repairs Type 1 lengths and CID system information, normalizes glyph names and symbolic flags, and adds cmap repair. Tests check width, CIDSet, and cmap behavior.
Audit fonts and update embedding
jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontAuditor.java, jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java, native/bridge/src/jpdfium_qpdf_fonts_embed.cpp, native/bridge/src/jpdfium_qpdf_fonts_subset.cpp, jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
The auditor identifies visible and corrupt embedded fonts. The embedder checks visibility and codepoint coverage, adds script-specific fallbacks, and incorporates corrupt fonts into embedding results. Native embedding preserves inherited ToUnicode maps and reports embedded-program validity.
Check PDF/A font conformance
jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontVeraPdfTest.java
VeraPDF tests check fixture, generated, and optional SafeDocs PDFs under selected PDF/A flavours. The test runner parses reports and selects font-related rules.

PDF repair

Layer / File(s) Summary
Prepare inputs and preserve signed documents
jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfRepair.java, jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfRepairTest.java
Repair checks signed and password-blocked inputs, attempts empty-password decryption where applicable, and normalizes malformed object tokens and repeated resource keys before repair. Tests check that signed inputs remain unchanged.
Recover pages and validate repair output
jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfRepair.java, native/bridge/src/jpdfium_repair.cpp, jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfRepairStructuralDamageTest.java, jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfRepairTest.java
Repair adds page-tree reconstruction and catalog-aware truncated-file salvage. It accepts salvage only when pages remain, rejects fixed output without pages, and compacts usable non-clean results. Tests cover malformed structures, page recovery, and encrypted input.

PDF compression

Layer / File(s) Summary
Check PDF detection and compression
jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorDetectionTest.java, jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
Tests cover single-quoted PDF/A attribute detection, Type1C and CID font subsetting, CID-to-GID remapping, and preservation of PDF/A-1 metadata and structure after compression.

PDF/X conversion

Layer / File(s) Summary
Check PDF/X conversion results
jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfXConverterTest.java
Tests check conversion of shading and DeviceN colorants to CMYK, removal of embedded-file entries and actions, and page-box normalization.

Possibly related issues

  • Stirling-Tools/JPDFium#191: The issue discusses signature loss during PDF operations; this change adds repair handling that returns qualifying signed documents unchanged and fails closed for marked signed inputs that cannot be opened or have no pages.

Possibly related PRs

  • Stirling-Tools/JPDFium#231: This PR introduces the font-embedding path that this change modifies in Java and native code.
  • Stirling-Tools/JPDFium#233: This PR uses the font-embedding path, whose behavior changes here and whose output is covered by PDF/X conversion tests.

Change: Bug fix

Merge Risk: High · up to efe2b

This change rewrites how damaged PDFs are repaired and how fonts are normalized and embedded. Several new paths can silently alter documents. Repaired files can lose pages, page order, images, inherited page settings, or catalog features such as forms and outlines. Font repair can display the wrong glyphs, undo subsetting, or produce invalid font tables. Healthy CFF fonts can be treated as corrupt. Signed documents can also bypass requested sanitization while being reported as clean. These issues should be fixed before merging.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description states the PR is tests-only and lists the changed test files, but it does not cover the native and main-code changes that the raw summary attributes to this PR. Those include the bridg… 1. Clarify scope. State whether native bridge, main-code (PdfRepair, PdfFontAuditor, PdfFontEmbedder), and header changes belong to this PR. If they do, describe them. If they belong to PR #295 or earlier stack PRs, name those PRs and confi…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: adding veraPDF-based PDF/A conformance validation tests. The changeset adds PdfFontVeraPdfTest, which validates outputs against PDF/A-1b, 2b, and 3b profiles. The titl…
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.
Full details: Title check

Explanation

The title names the main change: adding veraPDF-based PDF/A conformance validation tests. The changeset adds PdfFontVeraPdfTest, which validates outputs against PDF/A-1b, 2b, and 3b profiles. The title also omits the many font normalization and repair fixes, which is acceptable because the title need not cover every detail.

Full details: Description check

Explanation

The description states the PR is tests-only and lists the changed test files, but it does not cover the native and main-code changes that the raw summary attributes to this PR. Those include the bridge font normalizer, the SFNT cmap helpers, PdfRepair, PdfFontAuditor, and PdfFontEmbedder. The author says these moved to PR #295 and earlier stack PRs, yet the PR objectives describe the font normalization and repair changes as part of this PR. This conflict leaves the scope unclear. The checklist also leaves several items unchecked: the CHANGELOG entry, Javadoc for public members, and the header/ABI notes. The description does not link an issue, and the template asks for a 'Closes #(issue number)' line. Mostly complete, but scope and checklist gaps need resolution.

Resolution

  1. Clarify scope. State whether native bridge, main-code (PdfRepair, PdfFontAuditor, PdfFontEmbedder), and header changes belong to this PR. If they do, describe them. If they belong to PR #295 or earlier stack PRs, name those PRs and confirm this diff contains only tests. 2. Add a 'Closes #(issue number)' line or state that no issue applies. 3. Check the CHANGELOG entry under '## [Unreleased]', or explain why it does not apply. 4. Address the unchecked Javadoc and ABI items. Check them, or explain why they do not apply. The raw summary lists no public API changes, so note that explicitly. 5. Reconcile the checked 'integrationTest passes' item with the test command in the Testing section, and state whether './gradlew test' was run.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@balazs-szucs
balazs-szucs added this pull request to stack #298 November 15, 2026 12:00
@balazs-szucs
balazs-szucs force-pushed the test/verapdf-conformance-suite branch from da110bd to eab22d1 Compare November 15, 2026 13:43
@balazs-szucs
balazs-szucs force-pushed the test/verapdf-conformance-suite branch from eab22d1 to 697fa2f Compare November 15, 2026 13:54
@balazs-szucs
balazs-szucs force-pushed the test/verapdf-conformance-suite branch from 697fa2f to 4089969 Compare November 15, 2026 14:00
@balazs-szucs balazs-szucs reopened this Nov 15, 2026

@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: 9

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6fdecb6 and 4089969.

Files selected for processing: 4

  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorDetectionTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontVeraPdfTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfXConverterTest.java

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Review details

Context from checks skipped due to timeout: 1

  • GitHub Check: CodeRabbit
Additional context used

Code guidelines: 1

.github/CODERABBIT_REVIEW.md — configured
Path-based instructions: 3

Enforce meaningful assertions, deterministic concurrency, failure-path cleanup, and explicit native/stub requirements.

CodeRabbit configuration file

Files:

  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorDetectionTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontVeraPdfTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfXConverterTest.java
Apply the Java 25 and FFM rules from .github/CODERABBIT_REVIEW.md.

CodeRabbit configuration file

Files:

  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorDetectionTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontVeraPdfTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfXConverterTest.java
Source excerpt: These rules apply to maintained source.

CodeRabbit inference engine (.github/CODERABBIT_REVIEW.md)

Files:

  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorDetectionTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontVeraPdfTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfXConverterTest.java
ast-grep (0.51.1)

jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorDetectionTest.java

[warning] 44-46: Use a randomly-generated IV
Context: byte[] pdf = ("%PDF-1.7\n<rdf:Description pdfaid:part='1' "
+ "pdfaid:conformance='B'/>\n%%EOF")
.getBytes(StandardCharsets.ISO_8859_1);
Note: [CWE-329] Generation of Predictable IV with CBC Mode.

(random-iv)

jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java

[warning] 474-477: Use a randomly-generated IV
Context: byte[] mapBytes = new byte[] {
0, 0,
(byte) ((targetGid >>> 8) & 0xFF), (byte) (targetGid & 0xFF)
};
Note: [CWE-329] Generation of Predictable IV with CBC Mode.

(random-iv)

metadata.importXMPMetadata(xmp.getBytes(StandardCharsets.UTF_8));
metadata.getCOSObject().removeItem(COSName.FILTER);
doc.getDocumentCatalog().setMetadata(metadata);
doc.save(src.toFile());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Supported by static analysis

Script executed:

sed -n '560,620p' jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
grep -n -i pdfbox gradle/libs.versions.toml

Repository: Stirling-Tools/JPDFium

Length of output: 3225


Web query:

Apache PDFBox 3.0.8 PDDocument.save(File) default CompressParameters object stream xref stream compression PDF header version raised when compressing

Result:

Sources consulted:
- pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java at 832593c4 · apache/pdfbox — https://github.com/apache/pdfbox/blob/832593c4/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
- CompressParameters (Apache PDFBox 3.0.8 API) — https://javadoc.io/static/org.apache.pdfbox/pdfbox/3.0.8/org/apache/pdfbox/pdfwriter/compress/CompressParameters.html
- Apache PDFBox | PDFBox 3.0 Migration Guide — https://pdfbox.apache.org/3.0/migration.html
- pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java - pdfbox - Git at Google — https://apache.googlesource.com/pdfbox/%2B/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
- Document Persistence | apache/pdfbox | DeepWiki — https://deepwiki.com/apache/pdfbox/2.4-document-persistence

Script executed:

rg -n -F -e 'save(' -e 'CompressParameters' -e 'setVersion' -- jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.java || test "$?" -eq 1

Repository: Stirling-Tools/JPDFium

Length of output: 160


Script executed:

cat -n jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.java | grep -n -E 'save|CompressParameters|setVersion|NO_COMPRESSION|ObjStm|XRef' || test "$?" -eq 1

Repository: Stirling-Tools/JPDFium

Length of output: 888


Save the PDF/A-1 fixture without object or xref streams.

doc.save(src.toFile()) uses PDFBox's default compression. In PDFBox 3.0.8 this writes object streams and an xref stream, so the fixture does not keep the PDF 1.4 classic structure that the test assumes. The later assertions about absent ObjStm and XRef objects therefore run against an input that already violates the premise. Save the fixture with CompressParameters.NO_COMPRESSION, and assert that the serialized input has no object or xref streams before compression runs.

Suggested fix

-            doc.save(src.toFile());
+            doc.save(src.toFile(), CompressParameters.NO_COMPRESSION);

Add import org.apache.pdfbox.pdfwriter.compress.CompressParameters; if the file does not already import it.

.optimizeStreams(true)
.useZopfliDeflate(true)
.build());
try (PDDocument outDoc = Loader.loadPDF(res.bytes())) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Supported by static analysis

Script executed:

sed -n '560,620p' jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
grep -n -i 'DEFAULT\|qpdf\|actions\|fallback\|isPdfA\|pdfa' jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.java | head -120

Repository: Stirling-Tools/JPDFium

Length of output: 8208


Script executed:

set -u
echo "== PdfOptimizer flag constants and optimize signature =="
rg -n 'DEFAULT|QDF|LINEAR|OBJECT_STREAMS_DISABLE|OBJECT_STREAMS_PRESERVE|STREAM_DATA_COMPRESS|RECOMPRESS_FLATE|COMPRESS_STREAMS|static .* optimize\(' jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfOptimizer.java || test "$?" -eq 1
echo "== Native flag interpretation (QDF / linearize / null return) =="
rg -n -i 'qdf|linearize|flags' native/bridge/src jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java || test "$?" -eq 1
echo "== Pinned PDFBox version =="
rg -n -i 'pdfbox' gradle/libs.versions.toml || test "$?" -eq 1

Repository: Stirling-Tools/JPDFium

Length of output: 27662


Script executed:

set -u
echo "== QpdfLib.optimize body =="
sed -n '660,735p' jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java | cat -n
echo "== PdfOptimizer.optimize body =="
sed -n '48,72p' jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfOptimizer.java | cat -n
echo "== native validation and optimize_ex catch path =="
sed -n '336,360p' native/bridge/src/jpdfium_qpdf.cpp | cat -n
sed -n '446,478p' native/bridge/src/jpdfium_qpdf.cpp | cat -n
echo "== PdfDocument.saveBytes implementation =="
rg -n -F -- 'saveBytes' jpdfium/src/main/java/stirling/software/jpdfium/PdfDocument.java || test "$?" -eq 1

Repository: Stirling-Tools/JPDFium

Length of output: 8039


Assert that the PDF/A-1 qpdf pass produced the output under test.

compress keeps the unoptimized document bytes when the qpdf pass returns nothing or does not shrink the output. The test checks only the output structure, so it can pass on that fallback. With the current PdfOptimizer.DEFAULT (-1) flags, the native optimizer can reject the input because -1 sets both the QDF and linearization bits. If the fallback bytes have no object or xref streams and an uncompressed metadata stream, the three assertions pass without the PDF/A-1 qpdf pass running.

Assert the qpdf action before reading the output. The compressor adopts qpdf output only when it is smaller, so the fixture must contain content the qpdf pass can shrink:

Suggested assertion

--- "a/jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java"
+++ "b/jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java"
@@ -601,7 +601,10 @@
                             .optimizeStreams(true)
                             .useZopfliDeflate(true)
                             .build());
+            assertTrue(res.result().actions().contains(
+                    "qpdf: recompressed streams (object streams disabled for PDF/A-1)"),
+                    "PDF/A-1 qpdf pass must produce the output");
             try (PDDocument outDoc = Loader.loadPDF(res.bytes())) {
                 assertTrue(outDoc.getDocument()
                                 .getObjectsByType(COSName.getPDFName("ObjStm")).isEmpty(),
                         "PDF/A-1 must not contain object streams");

Until the DEFAULT flags are corrected, this assertion can fail.

Committable suggestion

IMPORTANT
Review the replacement and indentation, then test before committing.

Suggested change
try (PDDocument outDoc = Loader.loadPDF(res.bytes())) {
assertTrue(res.result().actions().contains(
"qpdf: recompressed streams (object streams disabled for PDF/A-1)"),
"PDF/A-1 qpdf pass must produce the output");
try (PDDocument outDoc = Loader.loadPDF(res.bytes())) {

int passed2b = 0;

for (Path pdf : candidates) {
byte[] bytes = Files.readAllBytes(pdf);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Stability & Availability · Quick win

Apply the size limit before reading the PDF.

Line 169 loads the complete file before Line 170 applies the 5 MiB limit. An oversized corpus file can exhaust the test worker's heap instead of being skipped. Check the file size first and use a bounded read.

As per coding guidelines, “Flag unbounded readAllBytes.”

Source: Coding guidelines

Comment on lines +175 to +176
} catch (Exception e) {
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Do not discard embedding failures.

If embedding throws for one selected PDF, this branch excludes that PDF from tested. Another successful PDF can then make the test pass. Fail with the input path and original exception, or collect the exception as a test failure.

As per coding guidelines, tests must have “No … swallowed failures.”

Source: Coding guidelines

assertNotNull(fontStream);
PDPage page = new PDPage();
doc.addPage(page);
PDType0Font font = PDType0Font.load(doc, fontStream, false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Supported by static analysis

Script executed:

sed -n '195,262p' jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontVeraPdfTest.java

Repository: Stirling-Tools/JPDFium

Length of output: 3899


Web query:

veraPDF PDF/A-2 rule 6.2.11.4.2 CIDSet applies to subset embedded CIDFonts only or all embedded CIDFonts, veraPDF 1.30 rule 6.3.5 CIDSet

Result:

Sources consulted:
- CIDSet, again — GitHub issue 811 in veraPDF/veraPDF-library (link omitted to avoid creating a cross-reference)
- Subset font question · Issue #907 · veraPDF/veraPDF-library — GitHub issue 907 in veraPDF/veraPDF-library (link omitted to avoid creating a cross-reference)
- preflight passes, veraPDF shows clause="6.2.11.4" error — GitHub issue 1019 in veraPDF/veraPDF-library (link omitted to avoid creating a cross-reference)
- Fix CIDSet / CharSet validation for PDF/A-1 — GitHub issue 983 in veraPDF/veraPDF-library (link omitted to avoid creating a cross-reference)
- TechNote 0010: Clarification of ISO 19005, parts 1-3 for developers of PDF/A creators and validators — https://pdfa.org/wp-content/uploads/2017/07/TechNote0010.pdf

Use a subset-tagged CIDFont fixture so the malformed CIDSet is checked under PDF/A-2b and 3b.

The fixture loads the font with embedSubset set to false, so the CIDFont has no subset tag on its BaseFont. For PDF/A-2b and PDF/A-3b, veraPDF checks CIDSet content only when that tag is present. The malformed CIDSet is therefore not flagged on this fixture, and the normalization assertions can pass with the CIDSet unchanged.

The fallback at line 232 has the same effect. When subsetFonts returns no PDF, the test validates the unsubsetted input and can pass without subsetting.

Make these changes in PdfFontVeraPdfTest:

  • Give the CIDFont BaseFont a six-uppercase-letter subset tag, for example ABCDEF+LiberationSans-Regular. Use a subset-tagged fixture for the malformed CIDSet case.
  • Assert that the malformed input fails the CIDSet rule under PDF/A-2b and PDF/A-3b before repair.
  • Assert that each repaired output passes the same rule.
  • Replace the fallback at line 232 with a failing assertion when subsetFonts returns no PDF, so the subset case must produce a subset output.

COSDictionary acro = doc.getDocumentCatalog().getCOSObject().getCOSDictionary(COSName.ACRO_FORM);
if (acro != null && acro.getCOSArray(COSName.FIELDS) != null) {
for (COSBase item : acro.getCOSArray(COSName.FIELDS)) {
if (item instanceof COSDictionary d) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Dereference field entries before checking their type.

PDFBox 3.0.8 returns raw entries from COSArray.iterator(). An indirect signature field is a COSObject, so this condition skips the signature assertion. Use indexed getObject(i) access before inspecting /FT. Verify that the assertion rejects an output that retains an indirect signature field. (raw.githubusercontent.com)

As per path instructions, “tests should have observable expected outcomes.”

Source: Path instructions

Comment on lines +476 to +477
if (clause.startsWith("6.2.11.8")) {
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Retain failures for references to .notdef.

Clause 6.2.11.8 prohibits references to .notdef in PDF/A-2 and PDF/A-3, including level B. This exclusion lets an output with that font violation satisfy the zero-violation assertions. Remove the blanket exclusion. If a fixture needs a validator workaround, restrict it to that fixture and the specific known failure. (github.com)

As per path instructions, “Enforce meaningful assertions.”

Source: Path instructions

dnFn.setItem(COSName.DOMAIN, cosFloats(0f, 1f));
dnFn.setItem(COSName.RANGE, cosFloats(0f, 1f, 0f, 1f, 0f, 1f));
try (var os = dnFn.createOutputStream()) {
os.write("{ 1 exch sub dup }".getBytes(StandardCharsets.US_ASCII));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Use a valid three-output tint transform.

With input 0.4, { 1 exch sub dup } leaves only two values, although /Range declares three. PDFBox 3.0.8 rejects this mismatch during evaluation. (raw.githubusercontent.com) The native converter appends RGB-to-CMYK instructions without checking the original output count, so structural assertions do not establish a usable result. (raw.githubusercontent.com)

Add the missing dup. Evaluate the input and converted tint transforms at a sample tint, and assert their expected component counts and values.

As per coding guidelines, tests need “an observable expected result” and must validate “representative rendering or text properties.”

Source: Coding guidelines

Comment on lines +1295 to +1296
assertEquals(new PDRectangle(0, 0, 200, 200).toString(), outPage.getTrimBox().toString());
assertEquals(new PDRectangle(0, 20, 150, 180).toString(), outPage.getCropBox().toString());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Check the persisted box coordinates without getter clipping.

PDFBox 3.0.8 clips getTrimBox() and getCropBox() to MediaBox. These assertions therefore pass even when conversion leaves both original out-of-range boxes unchanged. Correct handling of BleedBox does not detect that regression. (raw.githubusercontent.com)

Read the raw /TrimBox and /CropBox arrays from the page dictionary and compare their numeric coordinates. This makes the assertions verify normalization in the saved PDF.

As per path instructions, tests must have “observable expected outcomes.”

Source: Path instructions

@balazs-szucs
balazs-szucs force-pushed the test/verapdf-conformance-suite branch from 4089969 to 3059b6c Compare November 15, 2026 16:54

@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

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4089969 and e196eeb.

Files selected for processing: 4

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfRepair.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfRepairTest.java
  • native/bridge/src/jpdfium_qpdf_fonts_embed.cpp

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Review details

Context from checks skipped due to timeout: 1

  • GitHub Check: CodeRabbit
Additional context used

Code guidelines: 1

.github/CODERABBIT_REVIEW.md — configured
Path-based instructions: 4

Apply the native ownership, C ABI, C++23, engine integration, memory, and SIMD rules from .github/CODERABBIT_REVIEW.md.

CodeRabbit configuration file

Files:

  • native/bridge/src/jpdfium_qpdf_fonts_embed.cpp
Enforce meaningful assertions, deterministic concurrency, failure-path cleanup, and explicit native/stub requirements.

CodeRabbit configuration file

Files:

  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfRepairTest.java
Apply the Java 25 and FFM rules from .github/CODERABBIT_REVIEW.md.

CodeRabbit configuration file

Files:

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfRepair.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfRepairTest.java
Source excerpt: These rules apply to maintained source.

CodeRabbit inference engine (.github/CODERABBIT_REVIEW.md)

Files:

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfRepair.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfRepairTest.java
  • native/bridge/src/jpdfium_qpdf_fonts_embed.cpp
ast-grep (0.51.1)

jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfRepairTest.java

[warning] 413-413: Use a randomly-generated IV
Context: byte[] marker = "\n% /ByteRange [0 1 2 3]\n".getBytes(StandardCharsets.US_ASCII);
Note: [CWE-329] Generation of Predictable IV with CBC Mode.

(random-iv)

Comment on lines +152 to +153
RepairResult signed = signedDocumentResult(inputBytes, writeDiagnostics);
if (signed != null) return signed;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Major · Security & Privacy · Quick win

Reject incompatible sanitization requests instead of returning unsanitized success.

If an openable signed PDF contains JavaScript, embedded files or action annotations, sanitize(true) now returns CLEAN with the original bytes. This return bypasses PdfSecurity.sanitize. The same failure affects .all(), which enables sanitization.

Preserve the signature by returning an explicit failure for this incompatible request, or require an explicit policy that permits rewriting. Do not report successful sanitization without removing the requested content. Add a regression with an observable prohibited feature. As per coding guidelines, “Preserve stable public behavior.”

Source: Coding guidelines

if (pdf == null) return null;
boolean marker = contains(pdf, BYTE_RANGE);
try (PdfDocument doc = PdfDocument.open(pdf)) {
if (doc.pageCount() > 0 && (marker || doc.signatureCount() > 0)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Major · Functional Correctness · Quick win

Do not classify a raw /ByteRange occurrence as a signature.

The new test places /ByteRange in a comment in an unsigned PDF. This condition still treats that PDF as signed.

Append the same comment to the repairable zeroXref fixture. The guard returns either CLEAN with unchanged damaged bytes or FAILED, depending on whether PDFium opens it. Neither path attempts repair.

Confirm a signature structurally before disabling repair. Keep an unsigned-marker regression that expects repair to proceed. As per coding guidelines, “Preserve stable public behavior.”

Source: Coding guidelines

Comment on lines +962 to +964
byte[] input = identityCidPdf(source.baseName(),
"1 beginbfchar <0001> <0041> endbfchar");
input = withInheritedToUnicode(input);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Trivial · Maintainability & Code Quality · Quick win

Supported by static analysis

Script executed:

sed -n '100,145p' native/bridge/src/jpdfium_qpdf_fonts_embed.cpp
sed -n '520,560p' native/bridge/src/jpdfium_qpdf_fonts_embed.cpp
sed -n '940,995p' jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
rg -n 'UseCMap' jpdfium/src/test native/bridge/src

Repository: Stirling-Tools/JPDFium

Length of output: 8068


Script executed:

rg -n -F -e 'prepareMissingCidMapping(' -e 'setToUnicode(' -e 'setCjkToUnicode(' -e 'embedMissing(' -e 'codes' native/bridge/src/jpdfium_qpdf_fonts_embed.cpp || test "$?" -eq 1
echo '--- explicit/ToUnicode tests ---'
rg -n -F -e 'explicit' -e 'ToUnicode' -e 'embed(' jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java || test "$?" -eq 1
echo '--- caller window (first prepareMissingCidMapping call site) ---'
line=$(rg -n -F 'prepareMissingCidMapping(' native/bridge/src/jpdfium_qpdf_fonts_embed.cpp | sed -n '2p' | cut -d: -f1)
if [ -n "$line" ]; then start=$((line-30)); [ $start -lt 1 ] && start=1; cat -n native/bridge/src/jpdfium_qpdf_fonts_embed.cpp | sed -n "${start},$((line+30))p"; fi

Repository: Stirling-Tools/JPDFium

Length of output: 8163


Cover the setter guards with an explicit embed case.

inheritedToUnicodeBlocksCidSubstitution uses embedMissing. For a CID font without a program, prepareMissingCidMapping returns false on an inherited /ToUnicode, and the loop skips that font at line 898. The test therefore exits before setToUnicode or setCjkToUnicode runs. Removing the inheritance check from both setters leaves this test passing, and no other test exercises the setter guard for an inherited map.

Add an explicit PdfFontEmbedder.embed case for the same font, with an inherited /UseCMap base stream on /ToUnicode. The program must produce non-empty mappings. Both setters return on empty codes before the guard, so an empty case does not reach it. Assert that /ToUnicode still contains the base /UseCMap stream. Without the guard, the setter replaces that stream with a generated map, and the assertion fails.

Every defect fix needs a focused regression with an observable expected result, and this change currently lacks one for the setter guards.

@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

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d08ae6f and fcdc986.

Files selected for processing: 5

  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
  • native/bridge/src/jpdfium_font_normalizer.cpp
  • native/bridge/src/jpdfium_font_shared.cpp
  • native/bridge/src/jpdfium_qpdf_fonts_subset.cpp

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Review details

Context from checks skipped due to timeout: 1

  • GitHub Check: CodeRabbit
Additional context used

Code guidelines: 1

.github/CODERABBIT_REVIEW.md — configured
Path-based instructions: 4

Apply the native ownership, C ABI, C++23, engine integration, memory, and SIMD rules from .github/CODERABBIT_REVIEW.md.

CodeRabbit configuration file

Files:

  • native/bridge/src/jpdfium_font_normalizer.cpp
  • native/bridge/src/jpdfium_font_shared.cpp
  • native/bridge/src/jpdfium_qpdf_fonts_subset.cpp
Enforce meaningful assertions, deterministic concurrency, failure-path cleanup, and explicit native/stub requirements.

CodeRabbit configuration file

Files:

  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
Apply the Java 25 and FFM rules from .github/CODERABBIT_REVIEW.md.

CodeRabbit configuration file

Files:

  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
Source excerpt: These rules apply to maintained source.

CodeRabbit inference engine (.github/CODERABBIT_REVIEW.md)

Files:

  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
  • native/bridge/src/jpdfium_font_normalizer.cpp
  • native/bridge/src/jpdfium_font_shared.cpp
  • native/bridge/src/jpdfium_qpdf_fonts_subset.cpp
ast-grep (0.51.1)

jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java

[warning] 742-742: Use a randomly-generated IV
Context: byte[] staleCidSet = new byte[] {(byte) 0x80, 0, 0, 0, 0x08, 0, 0x20};
Note: [CWE-329] Generation of Predictable IV with CBC Mode.

(random-iv)

gid = (c + delta) & 0xFFFFU;
} else {
const size_t ro = ranges + k * 2 + range + (c - start) * 2;
if (ro + 2 > cmapOff + cmapLen) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Supported by static analysis

Script executed:

set -e
cat -n native/bridge/src/jpdfium_font_normalizer.cpp | sed -n '798,880p'
echo '--- cmap helpers / callers ---'
rg -n -F -e 'cmapFitsProgram' -e 'cidSetCanDescribeProgram' -e 'cmapLen' -- native/bridge/src/jpdfium_font_normalizer.cpp || test "$?" -eq 1
echo '--- format 4 subtable length handling anywhere in bridge ---'
rg -n -F -e 'idRangeOffset' -e 'segCount' -- native/bridge/src || test "$?" -eq 1

Repository: Stirling-Tools/JPDFium

Length of output: 7540


Bound format-4 cmap reads by the subtable's declared length.

cmapFitsProgram checks format-4 idRangeOffset lookups against the enclosing cmap table, not the subtable. A malformed format-4 subtable can therefore read the next subtable's bytes as glyph IDs. A nonzero value at or above maxGid makes the helper return false, and processFont then removes a valid /CIDSet on the non-resubsetted path. The format-4 length field at off + 2 is never read.

Limit the format-4 segment arrays and glyph-index reads to the subtable's declared end.

Suggested fix

--- "a/native/bridge/src/jpdfium_font_normalizer.cpp"
+++ "b/native/bridge/src/jpdfium_font_normalizer.cpp"
@@ -826,26 +826,27 @@
         const uint16_t fmt = readU16BE(b + off);
         if (fmt == 4 && cmapLen - rel >= 16) {
             const uint16_t segX2 = readU16BE(b + off + 6);
             const size_t segs = segX2 / 2;
+            const size_t subEnd = std::min<size_t>(off + readU16BE(b + off + 2), cmapOff + cmapLen);
             const size_t ends = off + 14;
             const size_t starts = ends + segX2 + 2;
             const size_t deltas = starts + segX2;
             const size_t ranges = deltas + segX2;
-            if (ranges + segX2 > cmapOff + cmapLen) continue;
+            if (ranges + segX2 > subEnd) continue;
             for (size_t k = 0; k < segs; ++k) {
                 const uint16_t end = readU16BE(b + ends + k * 2);
                 const uint16_t start = readU16BE(b + starts + k * 2);
                 const uint16_t delta = readU16BE(b + deltas + k * 2);
                 const uint16_t range = readU16BE(b + ranges + k * 2);
                 if (start > end) continue;
                 for (uint32_t c = start; c <= end; ++c) {
                     uint32_t gid = 0;
                     if (range == 0) {
                         gid = (c + delta) & 0xFFFFU;
                     } else {
                         const size_t ro = ranges + k * 2 + range + (c - start) * 2;
-                        if (ro + 2 > cmapOff + cmapLen) continue;
+                        if (ro + 2 > subEnd) continue;
                         const uint16_t raw = readU16BE(b + ro);
                         if (raw == 0) continue;
                         gid = (raw + delta) & 0xFFFFU;
                     }

Source: Learnings

Comment on lines +861 to +863
const uint32_t last = readU32BE(b + p + 4);
const uint32_t first = readU32BE(b + p + 8);
const uint32_t startGid = readU32BE(b + p + 12);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Major · Functional Correctness · Quick win

Supported by static analysis

Script executed:

sed -n '795,905p' native/bridge/src/jpdfium_font_normalizer.cpp

Repository: Stirling-Tools/JPDFium

Length of output: 5372


Read format-12 group fields from their own offsets.

In the format-12 branch, first and startGid use the wrong offsets. last at p + 4 is correct.

  • first reads p + 8, which is startGlyphID. It should read p, which holds startCharCode.
  • startGid reads p + 12. That is the next group's startCharCode, or bytes past the group array for the final group. It should read p + 8.

These errors have two effects:

  • For a multi-group table, startGid + (last - first) mixes a glyph ID with a character code. The result can reach maxGid, so cmapFitsProgram returns false. A valid font can then lose its existing /CIDSet.
  • For the final group, the p + 12 read covers four bytes past the group array. The guard at line 858 checks only groups * 12, so the read can pass the cmap table. If the cmap ends at the font-buffer end, the read leaves the buffer.

Add a regression test with a two-group format-12 cmap whose second group starts at a large character code. It should keep the CIDSet. Add a second test with the final group ending at the buffer boundary.

Suggested fix

--- "a/native/bridge/src/jpdfium_font_normalizer.cpp"
+++ "b/native/bridge/src/jpdfium_font_normalizer.cpp"
@@ -858,9 +858,9 @@
             if (base + static_cast<size_t>(groups) * 12 > cmapOff + cmapLen) continue;
             for (uint32_t g = 0; g < groups; ++g) {
                 const size_t p = base + static_cast<size_t>(g) * 12;
-                const uint32_t last = readU32BE(b + p + 4);
-                const uint32_t first = readU32BE(b + p + 8);
-                const uint32_t startGid = readU32BE(b + p + 12);
+                const uint32_t first = readU32BE(b + p);
+                const uint32_t last = readU32BE(b + p + 4);
+                const uint32_t startGid = readU32BE(b + p + 8);
                 (void)last;
                 if (first > last) continue;
                 if (startGid + (last - first) >= maxGid) return false;
Committable suggestion

IMPORTANT
Review the replacement and indentation, then test before committing.

Suggested change
const uint32_t last = readU32BE(b + p + 4);
const uint32_t first = readU32BE(b + p + 8);
const uint32_t startGid = readU32BE(b + p + 12);
const uint32_t first = readU32BE(b + p);
const uint32_t last = readU32BE(b + p + 4);
const uint32_t startGid = readU32BE(b + p + 8);

@balazs-szucs

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Action performed

Full review finished.

coderabbitai[bot]

This comment was marked as resolved.

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
@balazs-szucs
balazs-szucs force-pushed the test/verapdf-conformance-suite branch from 97fba7d to 5284fae Compare November 18, 2026 01:08
@balazs-szucs
balazs-szucs merged commit 5284fae into main Nov 18, 2026
14 checks passed
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.

1 participant