Commit Graph
8 Commits
Author SHA1 Message Date
Dylan M. Taylor 4ba6ff32b8 PDF functions and mesh shadings: charge retained values, refuse short tables, bound lattice rows and raster work (#2972)
* PDF functions and mesh shadings: charge retained values, refuse short tables, bound lattice rows and raster work

Depth-limit fallbacks were not charged to the function node budget; cached
copies of a function deep-copied its coefficient and program vectors while
only its nodes were charged; sampled functions made up missing samples as
zeros; calculator programs had no size limit; a lattice row was filled
before any limit applied; and overlapping mesh triangles each scanned their
whole bounding box.

The node is charged before the depth check; coefficients, bounds, encode
arrays and calculator operators are charged (eight to a node) so cached
copies carry their cost; a sampled function shorter than its table is
unsupported; calculator programs hold at most 4,096 operators; lattice rows
past the triangle limit are refused and vertices stop at it; and triangle
bounding boxes share a budget of 64 passes over the raster.

* address review: bound calculator token count while parsing

* address review: count skipped calculator tokens toward MAX_CALC_OPS

* address review: skip arrays and dictionaries in a calculator program without building them

* address review: scalar tokens in a skipped compound are passed over without building them
2026-11-11 15:12:55 -05:00
Dylan M. Taylor 0f200006fa EPS: bound copies, storage, text outlines, group nesting and font discovery (#2953)
* EPS: bound copies, storage, text outlines, group nesting and font discovery

The PostScript interpreter's numeric copy grew the operand stack past its
limit and charged nothing for the values copied; array and string
constructors retained storage without charging it; show and charpath copied
every glyph outline into the text path before any path or budget check; and
the font pre-scan searched the whole prefix again for every eexec, as the
bounding-box scan did for every rejected marker on a line. Clipping groups
also nested without limit.

Copies past the operand limit copy nothing; copies, arrays and strings count
against the operation budget; each outline is charged and checked against the
path limit before it is copied; headers are found in one pass and each is
tried once; a rejected bounding-box comment is skipped to its line end; and
the output builder drops groups past 256 open ones.

* address review: EPS font look-back stops at the previous font; charge input characters

* address review: count enclosing groups against the nesting limit in pattern and mask builders

* address review: close a replaced soft mask before nesting the new one; skip patterns whose wrappers pass the depth limit
2026-11-11 14:40:02 -05:00
becauseno7 25a7d98ebc PDF import: a trailer string in a stream does not trigger the window fallback
A `trailer` marker inside an unreferenced stream followed by `(` and more
than 4 KiB of text made the lexer stop at the window's end, so a later
`/Encrypt` name anywhere in the file refused a plain file. The unbounded
scan read a string there and opened it. The past-the-window fallback now
applies only when no object starts in the window or the first one opens
a dictionary (`<<`, including one split by the window's end).

Regression test with `trailer(` and `trailer[` in a stream and a later
Encrypt name.
2026-11-01 14:44:26 +06:00
becauseno7 98484975c4 PDF import: a name cut by the trailer window is read whole
The pre-scan window could end inside a trailer key, so a decoy like
`/Encrypted` cut right after `/Encrypt` was taken for the Encrypt key
and an unencrypted file was refused. A window that ends mid-token now
ends before that token instead, and the past-the-window fallback reads
the name whole (a real `/Encrypt` cut as `/Encryp|t` is still refused).

Tests for that boundary, for a trailer with a long /ID, and for `#`
without two hex digits staying as written in a name.
2026-11-01 13:31:59 +06:00
becauseno7 cd6c56b78d PDF import: the past-the-window /Encrypt fallback matches escaped names
The fallback searched for the literal bytes `/Encrypt`, so a long trailer
with the key written as `/Encr#79pt` (or any other #-escaped spelling) got
past it. It now finds the last name token that decodes to `Encrypt`, with
the lexer's own name decoding, and checks whether that token ends past the
window. It is still one linear pass per file. Longer names that only start
with `Encrypt` (`/Encrypted`) no longer count.
2026-10-31 22:07:29 +06:00
becauseno7 4319df2e59 PDF import: the encryption pre-scan reads a bounded window after each trailer (#2142)
The pre-scan lexed one object after every `trailer` marker over the rest of
the file, so an unterminated string or dictionary after each of many markers
made opening a crafted PDF quadratic. Each lex now gets a 4 KiB window; when
it runs out, the file is refused if `/Encrypt` appears past the window (one
search per file), so long trailers can't hide the key.
2026-10-30 14:46:34 +06:00
aiongg b7b75ed37a style: cargo fmt on the moved files 2026-10-26 21:54:30 +00:00
aiongg 576f1d1706 refactor(pdf): move loose test files to src/tests/ 2026-10-26 21:49:11 +00:00