Skip to content

M11: make PDF optimization safe and add a lossless profile - #1282

Draft
lukashold wants to merge 4 commits into
storytold:mainfrom
lukashold:codex/pdf-optimization
Draft

lukashold wants to merge 4 commits into
storytold:mainfrom
lukashold:codex/pdf-optimization

Conversation

@lukashold

@lukashold lukashold commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

PDF optimization could overflow on malformed image or mask dimensions, change other images when resampling a shared soft mask, and fail when a selected hidden-information category was already absent. Validate bounded dimensions and decoded sample lengths, give resampled masks a private reference, and handle only NothingToApply as a successful no-op. Count catalog /AF attachments and preserve absent hidden categories without silent mutations.

Add pdfcraft_optimize::Settings::lossless() and headless doc_optimize profile="lossless". Image streams, thumbnails, alternate images, tags, print settings, links, destinations and resource lists are retained. Non-image streams and document structure can still be compressed, and identical resources merged. Contradictory custom/discard options are rejected. Existing Reduce File Size defaults remain unchanged.

Validation of integration commit e9dd0e369bbc1028bd8ed12073f8f48425d81089:

  • Integration with main b5467d93: all eight cargo xtask ci gates passed, including 3,041 workspace tests (14 explicitly ignored), strict workspace/all-target Clippy, formatting, layers, 31 WebAssembly crates, assets, dependency/license policy and parity. Four test worker threads; optional external font/model inputs were not configured locally.
  • The subsequent main 3f044b62 printing update was merged without conflicts and checked separately: 462 print/UI/optimizer/sanitizer tests passed (one explicit ignore), together with strict workspace/all-target Clippy and all other gates above.
  • Actual CLI create/save/optimize/reopen/text/metadata/render checks passed. Before/after PNGs have identical SHA-256 6e3950f1cadc55b1d8b1c2955019640e3ce9d91527ab56412d5a0065cd0eed46 and were visually inspected. The 885-byte synthetic fixture verifies preservation, not compression ratio.
  • Regressions cover hostile dimensions, JPEG lengths, shared soft masks, lossless image/document preservation, absent hidden categories and catalog AF attachments.
  • The newer save-reporting fixture now contains real removable metadata: it still asserts a full rewrite after sanitization, while empty categories remain a no-op. Synthetic batch fixture timestamps are fixed for deterministic byte comparisons.

Full saves can remove old revisions and update modification dates; output is not guaranteed smaller. Additional codec coverage, a GUI preset manager and broad scan/perceptual-quality benchmarks remain outside this change.

Merge/release prerequisite: merge the independent generation-aware rewrite fix #1143 first, then repeat integration checks on combined main. It is open and unmerged; its implementation is not duplicated here. Hot Folder integration is separate in #1063.

AI assistance: implemented with OpenAI Codex for @lukashold.

Bound image decoding, preserve shared soft masks, and avoid mutations for absent hidden-data categories. Add the shared lossless optimization profile with conflicting-option refusal.

Retain existing UI repair provenance from a728aa4/ce0c0899 and the narrow Bulk harness hunk; preserve all original assertions.

Validated: 2438 workspace tests passed, 7 existing ignored; strict quality gates, 104 UI tests, 31 WASM packages and CLI preservation/refusal checks passed.

AI assistance: OpenAI Codex for @lukashold.

Co-authored-by: Chiranjeevi U <244287281+chiranjeevi-max@users.noreply.github.com>
lukashold and others added 2 commits October 13, 2026 23:10
Retain bounded image decoding, private resampled masks and lossless settings.
Preserve upstream UI and sanitizer changes, and make batch fixture timestamps
deterministic for byte-exact comparisons.

Co-authored-by: OpenAI Codex <noreply@openai.com>
Merge main 3f044b6 after strict checks, print/UI regressions, optimizer and sanitizer tests, WASM, assets, dependency policy and parity validation.

Co-authored-by: OpenAI Codex <noreply@openai.com>
Resolve against main's mono/JBIG2 optimization, ImageBudget decoding,
optimizer presets and the automation module split. The lossless profile
now also retains mono images and skips LZW re-encoding; image dimension
validation runs inside the shared ImageBudget allowance; masked images get
a private soft mask, counting the original mask's other users.

Main's own fixes for the batch fixture clock, OCR scan fixture and reload
language replace this branch's earlier test stabilizations; the
preferences-scroll test tweaks are dropped as out of scope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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

This branch has not been deployed

No deployments
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