Skip to content
This repository was archived by the owner on Nov 22, 2026. It is now read-only.

xlsx: zip 2.4.2 -> 9.0.4 (RUSTSEC-2026-0367/0368/0369); saves stay byte-identical - #11

Merged
drietsch merged 2 commits into
mainfrom
fix/zip-9
Oct 17, 2026
Merged

drietsch merged 2 commits into
mainfrom
fix/zip-9

Conversation

@drietsch

@drietsch drietsch commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

cargo deny on main fails on RUSTSEC-2026-0367, -0368 and -0369 against zip 2.4.2. All three are in ZipArchive::extract / ZipStreamReader::extract, which this repo never calls. The fix is zip >= 9.0.0, so this upgrades to 9.0.4 (the latest) instead of recording ignores. deny.toml is unchanged and its ignore list stays empty.

What changed

Dependency. zip = { version = "9.0.4", default-features = false, features = ["deflate-flate2"] } plus flate2 = { version = "1.1", default-features = false, features = ["rust_backend"] }, declared by sheet-xlsx. Both lockfiles move: the workspace and fuzz/. zopfli, displaydoc, crossbeam-utils, arbitrary and log leave the tree. typed-path comes in, and nix too, but only on macOS and the BSDs. flate2 1.1.10 and miniz_oxide 0.9.1 keep the same versions and the same enabled features on wasm32, macOS and Linux.

The deflate backend is pinned. zip 9's deflate feature switched from flate2 on miniz_oxide to zlib-rs plus zopfli. I built that variant and ran the comparison below: all 96 of 96 saves differed from the zip 2.4.2 output. So the workspace takes deflate-flate2 and selects the Rust backend itself. Note for later: flate2 prefers zlib-rs whenever any crate in the graph enables it, so a future dependency could switch the backend without notice. The new golden test would catch that.

Every option a save depends on is now set in one place. That is sheet_xlsx::write::part_options(), used by the package writer, the embedded empty workbook (SheetSession::new) and the CSV import:

  • Deflate at level 6.
  • Timestamp 1980-01-01 00:00:00. FileOptions::default() reads the clock whenever zip's time feature is on.
  • "Made by" set to Unix. Since zip 7.2 the default follows the build platform, so a Windows build would otherwise write different headers.
  • Mode 0o100644.
  • large_file off: no zip64 extra and no data descriptor.

API changes adapted:

  • FileOptions has a second lifetime, so the tests use SimpleFileOptions.
  • ZipFile::name() returns ZipResult<Cow<str>>. The OPC reader propagates the error and the test helpers unwrap it.
  • Name decoding now goes by the bytes rather than the entry's UTF-8 flag. Valid UTF-8 reads as UTF-8 with or without the flag. 2.x read a flagless non-ASCII name as CP437 and wrote the mojibake back. Anything else reads as CP437, where 2.x put U+FFFD in place of bad bytes in a flagged name. ASCII names read exactly as before, and all 495 part names in the corpus are ASCII.

The repo calls no raw_copy_*, extract or streaming API. by_index (the reader) and by_name (tests) are unchanged.

Byte identity

What this repo means by identity (ADR 503): untouched parts keep their decompressed bytes, and every part is written again, deflated by our own writer. Parts are not raw-copied with their original compression, and a save is not the same file Excel wrote. Neither statement was true before this change and neither is now. This PR changes no bytes of any save:

  • Every save path, compared with the zip 2.4.2 build's output, byte for byte. For each of the 47 workbooks in corpus/xlsx-corpus, xlsx-dynamic and xlsx-recalc: a zero-edit XlsxDocument save, a zero-edit SheetSession save, and an edit then save. Also a new workbook and a CSV import. Through the wasm build, 96 of 96 outputs are identical. Natively, 144 of 144 saves are identical, and so is the reader's view of every package: part names, order, lengths and content hashes.
  • New test sheet-conformance/tests/zip_container_bytes.rs. It pins the whole saved package, headers and deflate streams included, against goldens recorded from the zip 2.4.2 build. The cases are a new workbook, a CSV import, a zero-edit save of a package with unknown parts (customXml, a VBA project; calc chain dropped), a zero-edit save of the Excel-saved dynamic-array workbook (cm metadata, xl/metadata.xml, rich data), and an edited sheet. A failure names the first differing byte.
  • New test every_saved_entry_has_the_pinned_headers (same file). It covers every corpus workbook through three save paths (zero-edit document save, zero-edit session save, and an edit) plus a new workbook. For each one it reads the central directory and the local headers straight from the bytes, not through the zip crate, and checks every entry against the fields the zip 2.4.2 build wrote for all 1409 entries of those saves: version made by 0x0314 (Unix, 2.0), version needed 20, no data descriptor, deflate, timestamp 1980-01-01 00:00:00, no extra field, no comment, external attributes 0o100644. This answers the raw_copy_file question. zip 9's raw copy carries a source entry's extra fields, comment and attributes over, but this repo never raw-copies. An untouched part is written again from its stored bytes with part_options(), so none of the source's zip metadata reaches a save. For example, the dynamic-array fixture stores 0o600 and is saved with 0o100644.
  • The tests can fail. Setting unix_permissions(0o664) in part_options() makes all five tests in the file fail, and each failure names the byte or the entry and field.
  • The existing per-part tests stay green: xlsx_roundtrip (zero-edit identity, unknown parts, the pivot cache, [Content_Types].xml), spill_roundtrip (dynamic arrays), real_xlsx_corpus, xlsx_recalc_corpus and the xlsx_write_read property test.

Checks run locally

  • cargo deny check: advisories ok, bans ok, licenses ok, sources ok. No new ignores. The syn duplicate warning is gone with displaydoc.
  • cargo fmt --check and cargo check --workspace --all-targets pass, and so do both dependency guards.
  • cargo clippy --workspace --all-targets -- -D warnings: green in CI (check). Locally only cargo check --all-targets ran, because new executables were stalling at launch on the build machine.
  • cargo nextest run --workspace: 1495 passed, 5 skipped locally (before the header test was added; main had 1491). In CI at the head commit: 1496 passed, 5 skipped.
  • Coverage gate: GREEN, 438 implemented rows, 0 gaps.
  • REQUIRE_REAL_ENGINE=1 pnpm test against the wasm built from this branch: sheet-host-model 192 passed; sheet-bundle 339 passed, 1 skipped. The skip is the boot-failure path, which only runs when no artifact is present.
  • Fuzz smoke (nightly, 60 s per target, seeded from the corpora and fuzz/regressions/): xlsx_open ran 148,934 times and xlsx_load_recalc 143,731 times, both with no crash. parse_formula fails at parse_formula.rs:85, the same assertion main's nightly fuzz run has failed on since at least 2026-10-14. It touches only the formula parser and is unrelated to zip.

wasm size

sheet_js_bg.wasm, built with scripts/build-wasm.sh (wasm-bindgen 0.2.128, binaryen 119, -Oz): before 1,799,603 bytes (zip 2.4.2) → after 1,743,039 bytes (zip 9.0.4), −56,564 bytes (−3.1 %), against the 100 MB app budget. CI's wasm job: main 1,798,993 bytes, this branch 1,743,132 bytes. Most of the drop is zopfli. zip 2.x's deflate feature linked it in for levels above 9, which nothing here uses. The old artifact carries zopfli's panic paths and the new one does not.

Version

The bundle stays at 0.1.0-canary.22 here. The Rust change still moves the bundle hash, because Cargo.toml, Cargo.lock and the sheet-xlsx/sheet-js sources are inputs to scripts/source-hash.mjs. So node scripts/package-hash.mjs --check on this branch fails against the published canary.22, as expected. #10 already bumps to 0.1.0-canary.23. Bumping here too would make the two PRs race for the same number.

Whichever of the two merges second publishes canary.23 with both changes:

🤖 Generated with Claude Code

drietsch and others added 2 commits October 17, 2026 10:17
cargo-deny failed on RUSTSEC-2026-0367, -0368 and -0369 against zip
2.4.2. All three are in ZipArchive::extract / ZipStreamReader::extract,
which nothing here calls; the fix is zip >= 9.0.0, so the dependency is
upgraded rather than the advisories ignored. Both lockfiles move (the
workspace and fuzz/).

zip 9 changes what a writer gets by default, so every option a save
depends on is now stated in one place, sheet_xlsx::write::part_options,
used by the package writer, the embedded empty workbook and the CSV
import:

- Deflate stays on flate2's Rust backend (miniz_oxide) at level 6. zip
  9's `deflate` feature switched to zlib-rs plus zopfli; built that way,
  every save of the corpus came out different. The workspace takes
  `deflate-flate2` and pins the backend with a flate2 dependency in
  sheet-xlsx.
- "Made by" is pinned to Unix. Since zip 7.2 it follows the build
  platform, so a Windows build would have written different headers.
- The timestamp is pinned to 1980-01-01 00:00:00 and the mode to
  0o100644; `FileOptions::default()` reads the clock whenever zip's
  `time` feature is on.

API changes adapted: FileOptions gained a second lifetime (the tests use
SimpleFileOptions), and ZipFile::name returns ZipResult<Cow<str>>.
Names now decode by their bytes, not the entry's UTF-8 flag: valid
UTF-8 reads as UTF-8 with or without the flag (2.x read a flagless one
as CP437 and wrote the mojibake back), anything else as CP437 (2.x
replaced bad bytes in a flagged name with U+FFFD). ASCII names, all 495
part names in the corpus, read as before.

zip_container_bytes.rs pins the whole saved package, not only the
decompressed parts: a new workbook, a CSV import, zero-edit saves of a
package with unknown parts and of an Excel-saved dynamic-array workbook,
and an edited sheet. The goldens are the zip 2.4.2 build's output.

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

zip 9's raw_copy_file carries a source entry's extra fields, comment and
external attributes into the copy. This repo does not raw-copy: an
untouched part is written again from its stored bytes with
part_options(), so none of the source's zip metadata can reach a save.
The goldens show that for five packages; this test shows it for every
save path over all 47 corpus workbooks (zero-edit document save,
zero-edit session save, an edit) and a new workbook.

It reads the central directory and the local headers straight from the
bytes, not through the zip crate, and checks the fields the zip 2.4.2
build wrote for all 1409 entries of those saves: version made by 0x0314
(Unix, 2.0), version needed 20, no data descriptor, deflate, DOS
timestamp 1980-01-01 00:00:00, no extra field or comment, external
attributes 0o100644. With 0o664 in part_options, all five tests in the
file fail, this one naming the entry and the field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@drietsch
drietsch merged commit 3d5bd4a into main Oct 17, 2026
4 of 5 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant