Commit Graph
10 Commits
Author SHA1 Message Date
aiongg 8b4e4a8e90 refactor: deny unwrap, expect and panic in library and binary code
The library and the binary now deny clippy's unwrap_used, expect_used,
panic, unimplemented, todo and unreachable lints outside unit tests, and
forbid unsafe code. Malformed input must give an error or a warning,
never a panic.

The 36 offending calls are replaced without changing behaviour:

- Byte reads that converted a slice of checked length to an array now
  use the `Encoding::*_at` decoders, `first_chunk`, or a `Cursor`
  helper that returns `Result`; the fallbacks are the existing results
  for data of the wrong length (`Value::Other`, a skipped value, a
  short-data error).
- The fixed-offset readers of the header and the master pages build the
  array with `array::from_fn`; they index as before.
- `Node::set` returns the node it set, so `TextFramePreference` insets
  no longer look it up again with `expect`.
- The embedded value files fall back to no values if one fails to
  parse, and a block with a version bound that is not a number does not
  apply. A new unit test checks that every committed file parses and
  that every bound is a number.
- `Xml::end` without an open element fails a debug assertion and
  writes nothing in a release build.

diff_outputs.py over the corpus (without own/): 0 differing outputs,
0 changed failures, 0 changed warnings.

Idea from storytold/designcraft#98.
2026-10-08 04:18:22 +00:00
aiongg bb6fb3ef61 test: move writer tests into their modules; unit tests for tables and CJK objects
Tables and composite fonts, entries and kinsoku tables are tested on
synthetic objects, including big-endian composite font entries.
2026-10-07 19:59:06 +00:00
aiongg 53e730881d refactor: record audit reads through a recorder held by the database
The audit log was thread-local. Objects and attribute lists now carry the
recorder of the database they come from, so no conversion state is global.
2026-10-07 19:29:25 +00:00
aiongg bd9ee4490d refactor: carry the byte order and string tag in an Encoding instead of thread-locals
Add indd::convert, convert_file and convert_into, which return the IDML
package and typed warnings and keep no thread-local state.
2026-10-07 19:26:22 +00:00
aiongg 7ed2a1ab8c fix: guard against cyclic and oversized structures in damaged files
Groups that contain themselves or nest over 100 deep, style group cycles,
table counts larger than the cell data, slot numbers outside their page,
cyclic slotted-record continuations and non-finite numbers now give a
warning or an error instead of a crash or invalid output. Corpus output
is unchanged (tools/diff_outputs.py).
2026-10-07 18:26:48 +00:00
aiongg 3e89cad3bd fix: convert or clearly reject every file in the new sample batch
- Bullet list: the font style can be followed by 1 and four bytes.
- InDesign 2.0: in-object strings start with 1, not 2.
- InDesign 2.0-5.0: XML tag names are a flag byte and a string, in
  either byte order.
- InDesign 3.0 and 4.0: the document's hyperlink lists start at offset
  0 and include page destinations.
- XMP: the packet can be shorter than its object; take its length.
- InDesign 1.x files (no signature, DOCUMENT at 0x5C) are reported as
  not supported; files whose page directory lies beyond the database
  pages as having no object database.
- Schema: leave out hyperlink sources that hold an anchored object, and
  the characters U+FFFE and U+FFFF, which XML does not allow.

tests/corpus.rs accepts the two rejections above and skips the paths
listed in the local corpus/exclude.txt.
2026-10-07 06:27:26 +00:00
aiongg 1d0e27db32 feat: convert big-endian files from InDesign 3.0 and 4.0
The byte order flag applies to object data only: database pages stay
little-endian. Object data is decoded in the file's byte order, and in
big-endian data the string tag and the flag byte before it are swapped.

The two big-endian samples are also the only files from before
InDesign 7.0, and some of their layouts differ: page transform and
bounds chunks, font records, XML tag names and nodes, story strands and
40-byte guide records are read; text frame settings, document
preferences, a composite font and a section style are left out with a
warning. The 40-byte guides of an InDesign 7.0 file are now read too.

docs/format/big-endian.md records the evidence. The corpus tests now
cover all byte orders.
2026-10-07 03:11:04 +00:00
aiongg ff290551bd feat: parse object chunks and add a dump command
Objects are sequences of (u32 ID, u32 length, data) chunks. Add a cursor
for chunk data with the text segment encoding (single-byte and UTF-16
runs) and the in-object string format. `indd dump` prints an object's
chunks.
2026-10-06 16:07:27 +00:00
aiongg 1d96bb61ae feat: read the class and unclassed-UID trees
The master page holds three tree roots and counts: objects, the class of
each UID, and UIDs without a class. Database::class_of returns an
object's class ID, and `indd objects` prints it.
2026-10-06 16:01:30 +00:00
aiongg 326a851346 feat: read the object database
Decode the database pages: page trailers and types, the logical page
table, the object B+ tree keyed by (UID, segment), data pages, slotted
pages and continued records. Database::object returns any object's byte
stream. Add `indd objects` and `indd object` commands.

Every object of all 351 little-endian corpus files reads without an
inconsistency. Big-endian databases report Unsupported for now.

Add a project CLAUDE.md with the clean-room rules.
2026-10-06 15:57:48 +00:00