Commit Graph
15 Commits
Author SHA1 Message Date
bflatastic df29cd8f34 craft: list the new crates in the facade, and craft-cdr's write link names the function
Two more breaks on main from the merged PRs:
- crates/craft/Cargo.toml's [features] no longer matched the member crates
  (craft-ease, craft-pbr, craft-i18n-build and image-codecs' cms feature);
  regenerated with UPDATE_FACADE=1 cargo test -p craft -- integration::features.
- craft-cdr's crate docs (#2799) linked [`write`], which is both a function and
  a macro, so the strict docs build failed; it now links [`write()`].
2026-11-26 12:01:59 +07:00
BFlat 5ccff67dbc Merge pull request #2945 from dotCooCoo/fix/cmx-resync-known-chunk
craft-cdr: .cmx no longer drops a page that stray letters' length covers
2026-11-26 10:24:05 +07:00
dotCooCoo 7f6d211349 craft-cdr: .cmx recovery keeps a page whose check stops at a limit
When the chunk limit stopped the check of a page that the walk from the
chunk found reads, the recovery counted that page as one without
objects and could resume at a page inside the letters instead. The page
was then left out, and the read ended with the warning for limits and
no pages. A page whose check stops now keeps the reader at the chunk
found, as when the search runs out of work.
2026-11-23 04:47:29 -08:00
dotCooCoo f4b93c308e Merge main into feat/cdr-write 2026-11-22 15:52:22 -08:00
dotCooCoo 6188fffb10 craft-cdr: .cmx recovery judges a page a list cuts short without it as recovered
When the walk from the first chunk id reads a page cut short by the end
of a list and the walk from the inner page reads the whole page, the
recovery now compares where each read ends as well as where it starts.
The whole page counts as a chunk only the recovery reads, so it is kept
only when it reads with objects and without damage in its instructions.
2026-11-22 13:27:57 -08:00
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
dotCooCoo 430b7425fc craft-cdr: read the picture a .cdr file keeps of its drawing
`preview` returns that picture without reading the drawing, so an app can
show something for a file whose drawing it can't read. In versions 4 to
13 the picture is the RIFF form's `DISP` chunk, a bitmap that is returned
as a BMP file. Packages keep it as `metadata/thumbnails/thumbnail.bmp`
(versions 14 to 16) or `previews/thumbnail.png` (17 on). Versions 1 to 3
keep none.

The `DISP` walk stays within the RIFF form and the chunk count limit, and
the bitmap's color table, masks and rows must fit the chunk. A package
member is read within the member and inflate limits, with its CRC-32 and
signature checked. Rows R75 and R76 in PROVENANCE.md give the sources.
2026-11-22 06:48:52 -08:00
dotCooCoo 7b9b02bb0a craft-cdr: .cmx recovery compares the body each walk reads, not only where it starts
When the walk from an inner page reads a page inside a list that ends
before the page does, it reads that page without its body. The recovery
now treats that read as different from the whole page the walk from the
chunk found reads, so it no longer resumes at the inner page and drops the
page's objects.
2026-11-21 17:11:49 -08:00
dotCooCoo ca54da2114 craft-cdr: .cmx recovery walks enter lists and never stops a read that fits without it
When the chunks that only a recovery after stray bytes reads make a read
stop at a limit, the file is read again without the recovery, with the
warning for limits. The walks that decide a recovery enter lists as the
reader does and meet only at the same position inside the same lists, so
a page that the walk from the chunk found reads directly and the walk from
the inner page reads inside a list no longer rejects the recovery.

Tests cover both, check that a color table read without the recovery wins
over one only the recovery reads and that a table only the recovery reads
colors every page, and check that a recovered page past the object limit
is left out. The property tests compare pages by their layers and object
counts, since a table only the recovery reads may change colors.
2026-11-21 15:36:19 -08:00
dotCooCoo 39c54686f5 craft-cdr: .cmx no longer drops a page that stray letters' length covers
When stray bytes held four letters whose length covered the page chunk
after them, the reader resumed at those letters, read the page as their
body and dropped it without a warning.

After stray bytes the reader still resumes at the first chunk id it
finds. It resumes instead at a page chunk 8 to 64 bytes inside the body
of that chunk only when that chunk is one the reader passes over or a
page, the inner page reaches the outer chunk's end, the page reads with
objects and without damage in its instructions, and walking on from
both places reaches the same position or the end of the list within 16
steps, with every chunk read on the first walk also read on the second
(pages without objects aside). Of the chunks only the second walk
reads, the header or a table is used only when no other chunk of its
id is read. Letters spelling `page` whose length runs past the list are
checked the same way. In one read, the search for pages to resume at
spends at most four times the length of the RIFF form, or 1,048,576
when that is more, counting 64 for each step of a walk and the length
of each page body judged; past that, the reader resumes at the first
chunk id found. Pages kept this way are read after the other pages and
keep their place in the file. Each is judged again before it is read.
One that a limit stops, or leaves without objects, is left out with the
warning for limits; one the limits cut short is read as far as they
allow, as other pages are.

Resuming at an inner page, at a chunk the reader passes over that is
not followed by another chunk id or the end of the list, or after
letters whose length runs past the list adds the damage warning.

Tests read every file a second time with the recovery turned off and
check that a file this second read opens still opens, and that no page
it reads with objects is lost; both property tests do the same. R53 in
PROVENANCE.md states the rule.

Ports https://github.com/storytold/vectorcraft/pull/8866.
2026-11-21 14:56:56 -08:00
dotCooCoo a964eeca5c craft-cdr: refuse zero-width outlines and off-angle guideline points
A positive outline width that rounds to 0 coordinate units read back as
no width, so writing it now fails with `Unwritable`.

A guideline's second point near the corner of the coordinate range could
round to a point whose line ran up to 45 degrees off the stored angle.
The writer now takes a second point only when the line through the two
rounded points lies within 1 degree of the angle. When neither the full
reach nor the farthest in-range point qualifies, it walks the points the
line rounds to within 128 units of the start, and refuses the guideline
when none qualifies.
2026-11-21 01:36:06 -08:00
dotCooCoo 58996429d0 craft-cdr: number clipping containers 1, 2, 3 as sample files store them
Sample files of versions 7 to 15 hold the same stored id in a clipping
container's argument 8005 and in its group's `spnd`, even ids included,
so the halved reading of the container id in the specification is not
followed. Containers are numbered 1, 2, 3 and so on again, and R73
records the samples. The test reads argument 8005 from each `loda`
record and compares it with the `spnd` ids.

R64 also cites the magic rule that checks the `mimetype` member name,
and R65 no longer limits the `trfd` 0xFFFF field to version 15. The
crate README names the writer in its opening and Provenance sections.
2026-11-21 01:12:28 -08:00
dotCooCoo ffea9b22a0 craft-cdr: write version 15 .cdr drawings
`craft_cdr::write(&Drawing, Limits)` writes a drawing as a version 15
.cdr file: a ZIP package with a `mimetype` member and the RIFF file in
`content/riffData.cdr`. It writes pages and page sizes, the master
page's layers and guidelines, layer kinds with hidden and locked flags,
groups, clipping containers, paths, rectangles with corner radii,
ellipses, uniform fills and outlines (caps, joins, dashes, behind the
fill, scaled with the shape) in RGB, CMYK, gray, registration and spot
colors, the fill rule, opacity and blend modes. Fill and outline
records are shared by content.

Each record uses the layout the reader reads, by the PROVENANCE.md
rows it cites; rows R64 to R73 add the package's `mimetype` member,
the property-list, transform and flag fields, the point type bit that
marks editable nodes, the fill a uniform transparency names, layer ids
with the entries through which each page names the master page's
guides, desktop and grid layers, the outline record's layout, the
`mcfg` header, the `LIST filc` around each fill record, and odd
clipping container ids. A closed subpath ends with an explicit point at
its start. The fill rule and the direction of the opacity value follow
the reader's own reading of R47 and R52, as the README says.

Writing returns `WriteError::Limit` for a drawing the reader would not
read whole within the same `Limits`, and `WriteError::Unwritable` for
values the file cannot hold or would read back changed. The README's
Writing section and the `write` docs list both, with the changes a
read of the written file shows (rounding to what the file stores, and
what the reader leaves out of any file).

Tests in tests/it/write.rs read each written file back and compare it
with the drawing it came from, check each limit at the reader's
boundary, and check the refusals. The workspace README lists the crate.
2026-11-21 00:49:42 -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