[repo] V1: raster, meta, qr, pdf, save and the worker #1

Open
mnovak wants to merge 0 commits from feature/v1 into main
Owner

Day 1 (V1) of Pictor's public core: the crates the app's worker uses for the Toolbox, metadata, QR and the PDF workbench, plus the worker itself. Brief: the app repo's docs/roadmap.md (Prompt 1). Formats, the per-operation library choice and the worker protocol are in docs/FORMATS.md; every crate's licence is in docs/DEPENDENCIES.md.

What is in it

Crate What
raster probe/decode with pixel and size caps (checked from the header first), convert PNG/JPG/WebP/BMP/GIF/TIFF/ICO, crop, rotate, resize, Email/Web/Original presets, compress to a target size, HEIC through WIC with the codecs Windows has (none bundled)
meta read and strip EXIF/GPS/XMP/IPTC (JPEG, PNG, WebP and GIF at container level, pixels untouched; TIFF re-encoded losslessly) and PDF /Info + every XMP stream
qr text, URL, Wi-Fi and vCard payloads, PNG and SVG, colours with a contrast check, centre logo forcing level H
pdf pdfium for reading and rendering; lopdf for page operations, annotations with their own appearance streams, signature stamps, the redaction rebuild and AES-256 encryption; form fill; flatten; merge, split, images ↔ PDF
save atomic save (temp, flush, rename) with the .bak written first
worker pictor-worker.exe (JSON lines) and its client: a Job Object with a memory cap, time caps, and restart after a crash or hang

scripts/fetch-pdfium.ps1 pins pdfium chromium/8125 by sha256. fixtures-fetch/fetch.ps1 pins six fuzzed files from the pdf.js corpus. scripts/deps.mjs builds the crate table and fails on a licence outside the allowed set.

Tests (138, all green on c5a81ea; cargo test --workspace, clippy clean, node scripts/deps.mjs: 141 crates, 0 not allowed)

  • Redaction, 7 tests (the blocker). The fixture puts text, an image, a vector shape, a hidden layer, a note, a form field, Info, XMP, an outline, a struct tree and an attachment under or near the box. Afterwards none of the 12 secret strings is found by pdfium text extraction, by a lopdf scan of every string, name and stream (raw and decompressed), or by a raw byte grep. Page 2's content streams are byte-equal. The cases are plain, compressed, rotated, inherited resources and rotation, and encrypted input.
  • Hostile PDFs, 3 tests. 21 generated fixtures (truncated, broken or missing xref, self-containing page tree, parent loop, self-reference, 200k-deep arrays, a page count of 2^31, a 1e30 media box, a declared 1 GB stream, a 1 GiB deflate bomb, three broken fonts, an unknown security handler) plus 6 pinned pdf.js fuzz files go through the real worker: open, render, text, save and meta. Result over 111 operations: 92 ok, 18 typed errors, 1 out of memory (the bomb, killed at the 1 GB job cap and reported as such), 0 hangs, 0 unexplained crashes. A good PDF opens right after every bad one. The client also survives a deliberate abort, a 120 s hang (killed at 2 s) and a 3 GB allocation.
  • Hostile images, 11 tests. PNG/JPEG/GIF/TIFF bombs refused in under 1 s, truncated PNG and JPEG, a bogus ICO, empty and random input, and 300 xorshift mutations per fixture.
  • Metadata, 26 tests. After Remove all, GPS, camera, author and software are gone and the pixels are identical. Orientation is kept for JPEG. PDFs lose /Info and every XMP stream.
  • Save safety, 5 tests. A child process is killed while writing the content and while writing the .bak; the original is intact and the .bak is valid both times.
  • QR, 35 tests. Every payload round-trips through rqrr at every level, with colours and with three logo shapes.
  • Other, 51 tests. Pages, merge, split, images ↔ PDF, password on and off, owner-only passwords, search in view space, form fill (Czech values and a checkbox whose on-state is "Ano"), every annotation kind visible and with an appearance, Czech free text surviving flatten, a free text upright on a rotated page, and the signature stamp.

Self-review: what is weak or not done

  • Redaction rasterises the whole redacted page. Its text is no longer selectable, at 200 dpi JPEG. A content-stream rewrite was ruled out by analysis only, not by a measured prototype; the brief asked for a measurement and this PR gives an argument instead (FORMATS.md).
  • Redaction drops all bookmarks, even ones pointing at other pages. That is safe but blunt.
  • Hidden layers on unredacted pages stay, with a warning naming the pages. Removing them would break "other pages byte-equal". The brief says hidden layers are stripped; this is the conflict, and the code chose byte-equality.
  • Content shared between pages stays visible on the other pages. For example, a template stream reused on page 2 is left there.
  • Form fill relies on pdfium building appearances while it renders a form flagged NeedAppearances. That is undocumented behaviour. The tests prove it for text, Czech text and a combo box with pdfium 8125, so a pdfium bump must keep that test green.
  • Merge loses fillable forms and bookmarks of the merged files; their look is kept.
  • Free text uses Helvetica with WinAnsi plus 41 Central European letters. Anything else (Greek, Cyrillic, emoji) becomes "?". No font is embedded.
  • Opacity is drawn in the appearance stream only. There is no /CA on the annotation, so an editor that regenerates appearances may show it opaque. Notes have no popup annotation.
  • Editing a permission-restricted PDF (owner password only) saves it without restrictions. The original owner password is unknown. The app should say so.
  • TIFF strip loses the ICC profile and orientation, and multi-page TIFF is refused. PNG and WebP orientation stored in eXIf is not kept.
  • HEIC is untested with a real codec. This machine has the HEIF extension but no HEVC decoder. The "codec missing" path is tested; decoding and orientation of a real iPhone photo are not.
  • The "out of memory" detection reads the job's peak memory (≥ 90% of the cap). pdfium aborts silently, so this is inference, not a signal.
  • Interrupted saves leave .pictor-*.tmp files in the folder; nothing cleans them yet.
  • WebP output is lossless only (the image crate's encoder).
  • QR codes are not checked against a phone camera, only against rqrr.
  • Licences need Mark's confirmation for: ISC (rqrr, test only), Unicode-3.0, BSL-1.0 and CC0 among the crates, and inside pdfium.dll FreeType (FTL), libjpeg-turbo (IJG), libpng (Libpng-2.0) and ICU (Unicode-3.0). All are BSD/zlib-style with no licence deal, but not literally in the brief's list (DEPENDENCIES.md marks them).
  • The initial [repo] Init commit went straight to main: the empty repository needed a base branch for this PR.
  • Built and tested as a debug build only. The release build comes with the app.
Day 1 (V1) of Pictor's public core: the crates the app's worker uses for the Toolbox, metadata, QR and the PDF workbench, plus the worker itself. Brief: the app repo's `docs/roadmap.md` (Prompt 1). Formats, the per-operation library choice and the worker protocol are in `docs/FORMATS.md`; every crate's licence is in `docs/DEPENDENCIES.md`. ## What is in it | Crate | What | | :-- | :-- | | `raster` | probe/decode with pixel and size caps (checked from the header first), convert PNG/JPG/WebP/BMP/GIF/TIFF/ICO, crop, rotate, resize, Email/Web/Original presets, compress to a target size, HEIC through WIC with the codecs Windows has (none bundled) | | `meta` | read and strip EXIF/GPS/XMP/IPTC (JPEG, PNG, WebP and GIF at container level, pixels untouched; TIFF re-encoded losslessly) and PDF /Info + every XMP stream | | `qr` | text, URL, Wi-Fi and vCard payloads, PNG and SVG, colours with a contrast check, centre logo forcing level H | | `pdf` | pdfium for reading and rendering; lopdf for page operations, annotations with their own appearance streams, signature stamps, the redaction rebuild and AES-256 encryption; form fill; flatten; merge, split, images ↔ PDF | | `save` | atomic save (temp, flush, rename) with the .bak written first | | `worker` | `pictor-worker.exe` (JSON lines) and its client: a Job Object with a memory cap, time caps, and restart after a crash or hang | `scripts/fetch-pdfium.ps1` pins pdfium chromium/8125 by sha256. `fixtures-fetch/fetch.ps1` pins six fuzzed files from the pdf.js corpus. `scripts/deps.mjs` builds the crate table and fails on a licence outside the allowed set. ## Tests (138, all green on `c5a81ea`; `cargo test --workspace`, clippy clean, `node scripts/deps.mjs`: 141 crates, 0 not allowed) - **Redaction, 7 tests (the blocker).** The fixture puts text, an image, a vector shape, a hidden layer, a note, a form field, Info, XMP, an outline, a struct tree and an attachment under or near the box. Afterwards none of the 12 secret strings is found by pdfium text extraction, by a lopdf scan of every string, name and stream (raw and decompressed), or by a raw byte grep. Page 2's content streams are byte-equal. The cases are plain, compressed, rotated, inherited resources and rotation, and encrypted input. - **Hostile PDFs, 3 tests.** 21 generated fixtures (truncated, broken or missing xref, self-containing page tree, parent loop, self-reference, 200k-deep arrays, a page count of 2^31, a 1e30 media box, a declared 1 GB stream, a 1 GiB deflate bomb, three broken fonts, an unknown security handler) plus 6 pinned pdf.js fuzz files go through the real worker: open, render, text, save and meta. Result over 111 operations: 92 ok, 18 typed errors, 1 out of memory (the bomb, killed at the 1 GB job cap and reported as such), 0 hangs, 0 unexplained crashes. A good PDF opens right after every bad one. The client also survives a deliberate abort, a 120 s hang (killed at 2 s) and a 3 GB allocation. - **Hostile images, 11 tests.** PNG/JPEG/GIF/TIFF bombs refused in under 1 s, truncated PNG and JPEG, a bogus ICO, empty and random input, and 300 xorshift mutations per fixture. - **Metadata, 26 tests.** After Remove all, GPS, camera, author and software are gone and the pixels are identical. Orientation is kept for JPEG. PDFs lose /Info and every XMP stream. - **Save safety, 5 tests.** A child process is killed while writing the content and while writing the .bak; the original is intact and the .bak is valid both times. - **QR, 35 tests.** Every payload round-trips through rqrr at every level, with colours and with three logo shapes. - **Other, 51 tests.** Pages, merge, split, images ↔ PDF, password on and off, owner-only passwords, search in view space, form fill (Czech values and a checkbox whose on-state is "Ano"), every annotation kind visible and with an appearance, Czech free text surviving flatten, a free text upright on a rotated page, and the signature stamp. ## Self-review: what is weak or not done - **Redaction rasterises the whole redacted page.** Its text is no longer selectable, at 200 dpi JPEG. A content-stream rewrite was ruled out by analysis only, not by a measured prototype; the brief asked for a measurement and this PR gives an argument instead (FORMATS.md). - **Redaction drops all bookmarks**, even ones pointing at other pages. That is safe but blunt. - **Hidden layers on unredacted pages stay**, with a warning naming the pages. Removing them would break "other pages byte-equal". The brief says hidden layers are stripped; this is the conflict, and the code chose byte-equality. - **Content shared between pages stays visible on the other pages.** For example, a template stream reused on page 2 is left there. - **Form fill relies on pdfium building appearances** while it renders a form flagged NeedAppearances. That is undocumented behaviour. The tests prove it for text, Czech text and a combo box with pdfium 8125, so a pdfium bump must keep that test green. - **Merge loses fillable forms and bookmarks** of the merged files; their look is kept. - **Free text uses Helvetica with WinAnsi plus 41 Central European letters.** Anything else (Greek, Cyrillic, emoji) becomes "?". No font is embedded. - **Opacity is drawn in the appearance stream only.** There is no /CA on the annotation, so an editor that regenerates appearances may show it opaque. Notes have no popup annotation. - **Editing a permission-restricted PDF (owner password only) saves it without restrictions.** The original owner password is unknown. The app should say so. - **TIFF strip loses the ICC profile and orientation**, and multi-page TIFF is refused. PNG and WebP orientation stored in eXIf is not kept. - **HEIC is untested with a real codec.** This machine has the HEIF extension but no HEVC decoder. The "codec missing" path is tested; decoding and orientation of a real iPhone photo are not. - **The "out of memory" detection** reads the job's peak memory (≥ 90% of the cap). pdfium aborts silently, so this is inference, not a signal. - **Interrupted saves leave `.pictor-*.tmp` files** in the folder; nothing cleans them yet. - **WebP output is lossless only** (the image crate's encoder). - **QR codes are not checked against a phone camera**, only against rqrr. - **Licences need Mark's confirmation for:** ISC (rqrr, test only), Unicode-3.0, BSL-1.0 and CC0 among the crates, and inside pdfium.dll FreeType (FTL), libjpeg-turbo (IJG), libpng (Libpng-2.0) and ICU (Unicode-3.0). All are BSD/zlib-style with no licence deal, but not literally in the brief's list (DEPENDENCIES.md marks them). - **The initial `[repo] Init` commit went straight to `main`**: the empty repository needed a base branch for this PR. - **Built and tested as a debug build only.** The release build comes with the app.
mnovak added 13 commits 2026-11-16 14:00:40 +01:00
This branch is already included in the target branch. There is nothing to merge.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feature/v1:feature/v1
git checkout feature/v1
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mnovak/Pictor-public#1