Commit Graph
39 Commits
Author SHA1 Message Date
Brandon Thomas da1b44e44a Merge pull request #1527 2026-10-18 09:35:34 -04:00
BFlat 8f02f52a44 Merge pull request #1478 from midasmatterhorn/fix/cff-endchar-width-polarity
pdf: endchar takes its width by operand parity like the stems and rmoveto
2026-10-16 19:05:24 +07:00
bflatastic 9bdf05f34b Merge main into #1478; keep both sides of crates/pdf/src/cff.rs 2026-10-16 19:04:43 +07:00
bflatastic e37eec904d Merge main into #1565; keep both sides of crates/pdf/src/tests_import.rs 2026-10-16 19:04:34 +07:00
bflatastic 3ec09f20d4 Merge remote-tracking branch 'origin/main' into pr-1482
# Conflicts:
#	crates/pdf/src/cff.rs
2026-10-16 18:14:31 +07:00
BFlat 5bbd982c32 Merge pull request #1566 from midasmatterhorn/fix/r4-inline-len-overflow
pdf: an inline image with absurd dimensions falls back to the EI scan
2026-10-16 18:13:33 +07:00
BFlat 79bfc23c69 Merge pull request #1447 from midasmatterhorn/fix/glyph-name-char-boundary
pdf: don't slice glyph names at a non-char boundary in name_to_unicode
2026-10-16 18:12:24 +07:00
BFlat 896710b4c9 Merge pull request #1477 from midasmatterhorn/fix/cff-seac-recursion-depth
pdf: bound CFF endchar seac recursion so a cyclic font can't overflow the stack
2026-10-16 18:10:19 +07:00
bflatasticandClaude Opus 5.5 6f2f98b398 pdf: inline_len returns the checked product directly (clippy)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 17:48:08 +07:00
bflatasticandClaude Opus 5.5 f8b587503d pdf: rustfmt the inline-image test
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 17:36:55 +07:00
bflatasticandClaude Opus 5.5 183fe652e4 pdf: an inline image just under usize::MAX bytes doesn't overflow its end offset
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 17:36:11 +07:00
BFlat c044e7a872 Merge pull request #1543 from arnav-hiwarkar/fix/1536-ai-retain-layer-sizes
Import: Composition - Retain Layer Sizes for PDF / Illustrator files (#1536)
2026-10-16 17:02:43 +07:00
skylar taylor-barrickandCodex c2f790b1d9 refactor(pdf): share structure parsing through a bounded adapter
Load PDF document objects through the pinned craft-pdf parser and convert them into EffectCraft's existing drawing model with bounded traversal, recovery and retained data. Preserve generation numbers, stream limits, encrypted-document refusal and reported repairs.

Retain app-owned drawing, EPS, fonts and content/image decoding. Assert early excessive-nesting rejection without partial art, and cover tolerant arrays on native and WASM.

Validated with the22-stage local matrix and exact-head FreeBSD, Windows ARM64 and packaging checks.

Co-authored-by: Codex <noreply@openai.com>
2026-10-15 16:35:49 -06:00
midasmatterhorn 5e18a7fd92 pdf: an inline image with absurd dimensions falls back to the EI scan
inline_len computed (w * n * bpc).div_ceil(8) * h with Width/Height taken
straight from the content stream and no size validation — unlike decode()
and mask_image, which bound their geometry first. /W 5000000000000000000
overflows the multiply in debug and test builds; in release it wraps to a
small length and the caller slices the wrong bytes, misparsing the image
and shifting the EI resync.

Chain the arithmetic through checked_mul and return None, which the
caller already routes to the EI-scan fallback. Regression test:
inline_image_with_absurd_dimensions_falls_back_to_ei_scan — panics at
crates/pdf/src/image.rs:85 on main, passes with the chain.
2026-10-15 16:10:10 +03:00
midasmatterhorn 400379fd20 pdf: a soft mask at an unsupported bit depth is ignored, not fatal
mask_image read /BitsPerComponent from the attacker-controlled /SMask
dict with no validation and fed it straight into 1u32 << bpc — the main
image path rejects anything but 1|2|4|8|16 before its own identical
shift, the mask path did not. /BitsPerComponent 32 panics in debug and
test builds and wraps the shift in release, mistranslating every sample
into alpha.

Mirror decode()'s depth check: an unsupported mask depth means no usable
mask, so the image draws with the mask treated as absent. Regression
test: smask_with_absurd_bpc_is_ignored_not_fatal — panics at
crates/pdf/src/image.rs:184 on main, passes with the check.
2026-10-15 16:05:32 +03:00
.CooCoo 26ed1a35bf fix(pdf): prevent overflow in EPS integer arithmetic
Use checked division and remainder for EPS integer operators so i64::MIN with a divisor truncating to -1 cannot panic. Preserve the existing zero-divisor fallback and normal truncation behavior.

Add public EPS parse regressions covering extreme, fractional and ordinary operands.

PR #1223
2026-10-15 02:09:25 -06:00
arnav-hiwarkarandClaude Opus 5.5 2d216151c6 Import: Composition - Retain Layer Sizes for PDF / Illustrator files (#1536)
The PDF / Illustrator import dialog now offers Composition - Retain Layer
Sizes. Each file layer's footage is cropped to its artwork bounds (fills,
stroke outlines, images, clips) and positioned to keep its place on the
page. Decoding, continuous rasterisation, shape conversion and reload share
one crop (effectcraft_pdf::layer_doc_with_sizes), so they agree.

Also collapses a match guard in the STL reader for current stable clippy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 13:33:50 +05:30
midasmatterhorn c6736d8fc0 pdf: checked_add for CFF Private DICT and Type 1 RD offsets from the file 2026-10-14 22:57:37 +03:00
midasmatterhorn 790e2387d6 pdf: endchar takes its width by operand parity like the stems and rmoveto 2026-10-14 22:56:27 +03:00
midasmatterhorn 769a019e7d pdf: bound CFF endchar seac recursion so a cyclic font can't overflow the stack 2026-10-14 22:55:46 +03:00
dotCooCoo 2f437ea551 EPS and PDF: huge arcs, long paths and loop passes count against the import's limits
The EPS interpreter counted one operation against its budget for each
name it ran, whatever the operator did, and paths had no length limit.
Parsing one arc at a radius of 10^300 passed 3 GiB of resident memory
within 43 seconds. A loop of arc at a radius of 2.2 x 10^18 was still
running after 60 seconds, and a loop of pathbbox on a path of 100,001
elements and { {} loop } loop did not finish within 20 seconds. PDF
content had no path limit either: parsing a page that repeats
0 0 1 1 re 4,000,000 times peaked at 2.3 GiB of resident memory.

A path now holds at most 1,048,576 elements (MAX_PATH, the limit of
VectorCraft's EPS interpreter). In EPS, moveto, lineto, curveto,
closepath, arc, charpath and the rect operators check it, and an
operator that would take a path past it stops the program with
"PostScript (path limit)". In PDF, m, l, c, v, y, h and re (each adds
at most five elements) stop the content stream with
"content (path limit)" when the path already holds more than 1,048,571.
Each path element an operator makes, reads or copies (arc, rectangle
arrays, charpath, pathbbox, clip, eoclip, gsave, save) now counts
against the EPS budget. Each pass of repeat, for, loop and forall
counts too, and so does each procedure item that is not a name. A
moveto right after a moveto replaces it, as the PostScript Language
Reference describes, so text placed with moveto and show leaves one
element.

Five tests in tests_import.rs cover the loops, the path limit in both
interpreters and runs of moveto and show.
2026-10-14 10:19:05 -07:00
midasmatterhorn c3b88d0d76 pdf: don't slice glyph names at a non-char boundary in name_to_unicode 2026-10-14 18:01:41 +03:00
dotCooCoo 767120f6ca EPS: arc and arcn with huge angles no longer hang the import
arc added 2π to its sweep in a loop until the sweep was no longer
negative, and arcn subtracted 2π the same way. For an angle of 10^18
degrees the loop took about 3e15 passes, and from 2^56 radians (about
4.1e18 degrees) up, adding 2π left the sweep unchanged and the loop
never ended. A sweep that needed no loop, as in 0 10^18 arc, was passed
unchanged to kurbo, which divides it into more than 1e16 curves (about
four per turn at a radius of 10), and arc appended each curve to the
path. Importing an EPS file probes it with effectcraft_pdf::parse,
which has no time limit, so importing such a file did not finish.

As in storytold/vectorcraft#1062, every arc now starts at the first
angle's remainder after whole turns, and when the second angle is below
the first (arc) or above it (arcn), the sweep is worked out from the
two angles' remainders. A sweep of up to 1,024 turns is drawn whole.
For a longer one, the import records a skip note
("arc (too many turns)") and leaves out whole pairs of turns, so that
between 1,022 and 1,024 turns remain. The arc still ends at the second
angle, and an even-odd fill covers the same area as the full sweep.

Arcs of up to 1,024 turns whose angles are within about 10^6 degrees
are unchanged apart from rounding, except some whose angles are a whole
number of turns apart or within rounding of that. For larger angles,
the old conversion to radians lost precision: at 10^15 degrees, a
quarter-turn arc swept 1.5723 radians instead of 1.5708.

When raising (arc) or lowering (arcn) the second angle by whole turns
makes it equal to the first, as in 7 -353 arc or 2 362 arcn, rounding
sometimes made the old loop add a turn and draw a full circle. Those
arcs are now empty, as the PostScript Language Reference defines them.
When the raised or lowered angle falls just short of the first
instead, the reference defines a full circle, and each version leaves
some of these arcs empty: the old code drew nothing for
125.00000000000001 125 arc, which the new code draws as a full circle,
and the new code draws nothing for 1.0000000000000002 -719 arc, which
the old code drew as a full circle.

arcs_with_huge_angles_end_at_their_second_angle parses each program on
a thread of its own and fails when no result arrives within 20 seconds.
2026-10-12 08:35:18 -07:00
tylerjenningsw 75cc264ccf Lint: clippy's collapsible_match passes on Rust 1.95
cargo +1.95 clippy --workspace --all-targets --release -- -D warnings
stopped on seven `if` blocks that clippy wants folded into their match
arm (psd, text, effects x2, pdf x2, render). Each becomes a match guard.
The behaviour is unchanged: when a guard is false the value falls through
to arms that can't match it and then to `_ => {}`. The one exception is
the PDF PostScript calculator, where a `{` past the nesting limit would
fall through to the operator arm; it keeps its own no-op arm, so it is
still skipped rather than pushed as an operator.
2026-10-10 16:54:16 -04:00
Claude 2013ec318a Merge pull request #557 from haranishi/fix/pdf-inflate-limit 2026-10-10 12:51:15 +00:00
Ikki NishiharaandClaude Sonnet 5.5 ff38282674 PDF colour spaces and functions: bound sizes, depth and stacks
A PDF could abort the process through its colour spaces and functions.
An Indexed hival of 10^12 asked an image for a 24 TB palette. A sampled
function's outputs (one per /Range pair) multiplied its table without a
bound, and copies of the table (one per q, one per reference) multiplied
it again. Self-referencing colour spaces and functions overflowed the
stack, a calculator's copy doubled its operand stack, index, idiv and
mod could panic, and f64::clamp panicked on a reversed /Domain or
/Range. Clamp hival to 255, count samples with checked arithmetic (at
most 32 inputs and outputs, 2^24 samples a table), share the samples,
give one function read a budget of nodes and samples, limit nesting to
8 levels and the calculator stack to 100, and clamp with the bounds in
either order.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-10 20:29:28 +09:00
Ikki NishiharaandClaude Sonnet 5.5 6364ddf555 PDF: bound what every stream filter may decode to
decode_stream_within now bounds the output of each stage of a /Filter
chain, not only FlateDecode. RunLength, LZW, ASCIIHex and ASCII85 stop
when their output would pass the limit, a full LZW table takes no more
entries, PNG predictor rows are sized with checked arithmetic and only
allocated when a whole row fits in the data, and CCITT checks
/Rows x row bytes against the limit before allocating.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-10 18:12:06 +09:00
Ikki NishiharaandClaude Sonnet 5.5 8c665a19e2 PDF: bound what a FlateDecode stream may inflate to
inflate used the unbounded miniz_oxide functions, and File::parse decodes
every object stream eagerly. Use the limit variants (1 GiB per stream, 256 MiB
for object streams, a quarter of that on 32-bit targets) and bound the
truncated-stream salvage buffer too.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-10 17:29:44 +09:00
Dexter 39e6907b5f G2: improve editing reliability and Windows rendering fidelity 2026-10-06 00:00:31 -05:00
Brandon ThomasandClaude Opus 5.5 e910858445 Never crash: PostScript radix numbers outside 2..=36
In EPS/PostScript, `0#7` asked i64::from_str_radix for radix 0, which panics (found by
fuzzing). Radixes outside 2..=36 are not numbers now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 14:21:14 -04:00
Brandon ThomasandClaude Opus 5.5 8e4e29844e Never crash: PDF close-path operators and CFF outlines without a current point
The s, b and b* operators closed the path even when there was no current point, which kurbo
asserts against (a panic in debug builds; found by fuzzing). Close only when a subpath is open.
CFF charstrings that draw before their first rmoveto now start the subpath at the current
point, as Type 1 charstrings already did. Denies the panic lints in the crate (it had no panic
sites).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 12:15:02 -04:00
Brandon ThomasandClaude Opus 5.5 5db4bff461 M13.12: docs (pdf README, parity, plug-ins), EPS Type 3 fonts reported
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 09:51:22 -04:00
Brandon ThomasandClaude Opus 5.5 740faf1c1f M13.12: EPS text (show variants, charpath, stringwidth, embedded Type 1/CFF, fallback fonts)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 09:01:10 -04:00
Brandon ThomasandClaude Opus 5.5 d0df520bc1 M13.12: pdf CCITT G3/G4 images, parser robustness tests and panic fixes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 08:54:05 -04:00
Brandon ThomasandClaude Opus 5.5 3d536cfe5a M13.12: pdf /W2 and /DW2 vertical metrics, CMap WMode
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 08:48:25 -04:00
Brandon ThomasandClaude Opus 5.5 d15b69c734 M13.12: pdf knockout/isolated transparency groups, group alpha and masks on group results
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 08:46:41 -04:00
Brandon ThomasandClaude Opus 5.5 b0b8d4c01a M13.12: pdf mesh shadings (types 4-7) and function-based shadings
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 08:42:49 -04:00
Brandon ThomasandClaude Opus 5.5 7d944ca494 M13.6: PDF/AI text, images, tiling patterns, blend modes, soft masks, pages; clip groups to masks / Merge Paths
Text with embedded TrueType, CFF (Type1C / CIDFontType0C / OpenType), Type 1 and Type 3 fonts,
standard-14 fallback to the bundled OFL fonts; Flate / DCT / inline / stencil images with SMask,
Indexed and ICC alternates; luminosity / alpha soft masks and the 16 blend modes in the SVG
render tree; tiling patterns; calculator functions; file.import page and Footage::page;
Create Shapes from Vector Layer keeps clips (page clips as layer masks, nested clips as Merge
Paths Intersect).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 05:49:36 -04:00
Brandon ThomasandClaude Opus 5.5 da0ec526f3 M13.2: PDF / Illustrator (.ai) / EPS vector footage (effectcraft-pdf): continuous rasterisation, layered composition import, Create Shapes from Vector Layer; SVG render tree clip groups
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 04:12:21 -04:00