Commit Graph
3 Commits
Author SHA1 Message Date
dotCooCoo e751a7a49c craft-cdr: refuse previews that preview cannot read whole
preview now reads a DISP chunk only when its first 4 bytes are
08 00 00 00 (every DISP chunk in the sample files starts so) and its
bitmap has a 40-byte info header, a plane count of 1 and uncompressed
pixels: compression 0 at 1, 4, 8, 16, 24 or 32 bits, or compression 3
(color masks) at 16 or 32 bits, as the bitmap info header page states.
A color table may not hold more than 2^bit count colors, and the
image size must be 0 or the rows' size, as in every sample. Other bit
counts with those compressions fail as damaged; other header lengths
and compressions are refused as unsupported. A DISP chunk of another
kind, or a bitmap with another header length or compression, is passed
over, and a file with no later DISP bitmap that preview reads is
refused as unsupported. Before this, a bit count of 0, compression 6 or a header
of another length gave a BMP file whose pixel offset was wrong, and
the rows were checked only for compressions 0 and 3. The row size is
now computed in 64 bits, so 32-bit targets accept the same bitmaps as
64-bit ones. The BMP file ends with the last row: bytes after it in the
chunk are left out, and the file's memory is reserved fallibly.

A RIFF file without a DISP bitmap now gives Ok(None) only when its
last chunk ends where the form's length says, inside the file. A chunk
that runs past the form, a partial chunk header at the end, a file cut
short or a form length too short for the form type fails as damaged,
since the missing bytes may hold the picture. A file cut short still
gives a DISP chunk it holds whole.

A version 2 file keeps a 1-bit picture (R40) that preview does not
read, so preview refuses it as unsupported instead of reporting no
picture. Version 1 still gives Ok(None).

Tests cover each of these cases, a package that holds both thumbnail
members, and the package member count limit. The hostile-input
property tests in tests/it/read.rs now also run preview, including
deflated thumbnail members and a compressed list before the DISP
chunk, and check that a package without a picture member gives
Ok(None) whatever its damaged drawing holds.

The README and the preview doc comment say that preview does not check
the drawing's version. PROVENANCE.md row R76 records that no sample
package's RIFF stream has a DISP chunk, and the crate description
mentions the preview.
2026-11-22 07:42:50 -08:00
Dylan M. TayloranddotCooCoo 9b28b56bc7 craft-cdr: look up clipped objects' own chunks once (port vectorcraft#8862) (#2727)
Ports @dotCooCoo's clipped-group lookup accounting and regression test
() from storytold/vectorcraft#8862
into craft-cdr (#778, storytold/vectorcraft#8857).

Co-authored-by: dotCooCoo <RobertLeeLW@gmail.com>
2026-11-20 19:30:33 -05:00
Dylan M. TayloranddotCooCoo 75d179f8df craft-cdr: move VectorCraft's bounded CDR/CMX reader into craft-libs (#2697)
* craft-cdr: move VectorCraft's bounded CDR/CMX reader into craft-libs (#778)

Moves crates/cdr (vectorcraft-cdr, landed in storytold/vectorcraft#8632)
to craft-libs as craft-cdr: legacy WL (v1-v2), RIFF/cmpr (v3-v13),
ZIP packages and data streams (v14-v27), .cmx (32-bit), provenance
(R1-R63), synthetic test builders, and integration tests.

Co-authored-by: dotCooCoo <RobertLeeLW@gmail.com>

* craft-cdr: address CodeRabbit review findings

- Classify all-zero CMX dash patterns once in Tables::read instead of per-curve
- Validate loda offset table length before reserving offsets Vec capacity

---------

Co-authored-by: dotCooCoo <RobertLeeLW@gmail.com>
2026-11-20 19:12:32 -05:00