Files
wordcraft/crates/engine
130c2dab40 HTML import: pictures referenced by a relative path are embedded (#98) (#113)
* HTML import: pictures referenced by a relative path are embedded (#98)

An img whose src was a path next to the HTML file was dropped, leaving
only its alt text; only data: URIs loaded. The HTML importer now takes
an optional image loader (the formats crate stays free of file access
and wasm-safe), and opening an HTML file from disk loads relative
sources from the file's folder. URLs and absolute paths are not
followed, and files that aren't pictures are ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* HTML import: relative pictures stay in the folder, read only regular files, within a budget (#98)

Review follow-up for #113. Pictures named by a relative path are now
loaded by LocalImages:

- Only regular files are read. The path is checked before opening (a
  named pipe would block the open), the opened handle is checked again,
  and the read goes through take(limit + 1), so the per-picture limit
  holds even for files that report a length of 0, like /dev/zero.
- The path is canonicalized and must stay inside the HTML file's
  folder, so `..` and symlinks can't reach other files.
- Each file is read once and shared between references, and every
  reference counts against a 1 GB budget for the document, so one large
  picture referenced many times can't make the import read or copy
  without bound. Bytes read from oversized files count too.

The image loader now returns Arc<Vec<u8>>, and make_img takes either a
Vec or an Arc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: lloyd <lloyd@stackworx.io>
Co-authored-by: Brandon Thomas <echelon@gmail.com>
2026-10-10 07:50:09 -04:00
..