mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-31 05:36:46 -06:00
`Table::new` allocates `rows * cols` cells up front, and the counts reach it from IDML and DOCX, where they are whatever the file claims. Measured here: `size_of::<Cell>()` is 1,360 bytes, so the reported IDML case -- one `<Table>` with 5,000 `<Row/>` and 5,000 `<Column/>`, about 1 KB zipped -- asks for 25M cells, some 34 GB. That allocation does not fail politely: it aborts the process through `handle_alloc_error`, which no `catch_unwind` can catch, so every open document's unsaved work goes with it. A table is clamped to InDesign's own limits, 10,000 rows and 1,000 columns, and to 250,000 cells whatever its shape -- the row and column limits alone would still allow 13.6 GB. Columns are clamped first and rows take what is left, because a table is far more often long than wide. The IDML importer walks the clamped slices and reports the difference. Indexing its rows and columns by the file's own counts would be out of bounds, which is how a 34 GB abort would otherwise have become a panic. Rebased onto the post-split main: the constants and `clamped_size` live in `doc`'s `table` module root, `Table::new` in `table/grid.rs`, and the IDML table reader in `import/table.rs`.