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.
`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.
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>