Skip to content

fix(writer): rvt-write --dry-run checks what the write would refuse, a patch is refused that frames a stream otherwise than it is stored, and an empty or self-copying write is a plain copy (#1885) - #1893

Merged
DrunkOnJava merged 4 commits into
mainfrom
fix/1885-rvt-write
Nov 13, 2026

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Items 1 to 7 of #1885, the rvt-write and writer.rs half. rvt-write --dry-run checks what the write would refuse, a patch that frames a stream otherwise than it is stored is refused, a base64 value that empties a stream is refused, and an empty manifest or a file copied onto itself is a plain copy. Part of #1885.

Stacked on #1891, whose rvt::cli::same_file this uses: its branch is merged into this one (863eb146), so the diff shows its commits until #1891 lands; merge #1891 first and this PR's own change is what remains.

Motivation

Batch 5's audit of the write path (main at e57db423; each finding confirmed by a second reader, items 1, 2 and 8 also re-read by the maintainer session):

  • 1 and 2. --patches is required even with --dry-run (it is unwrapped before dry_run is looked at), so the manifest-less dry run the flag's help documents is unreachable; and the dry run exits 0 without checking that the streams exist or applying the writer's own refusals (writer.rs:206-217).
  • 3. The manifest alone picks a stream's on-disk framing (writer.rs:197, :705) and verification reads back with the same framing, so a Formats/Latest written with the wrong framing passes.
  • 4. A pad-only base64 value ("=") decodes to zero bytes and silently empties the stream.
  • 5. An empty patches array writes the copy and then exits 1 with 0 stream(s) failed verification: all_matched is false for zero streams.
  • 6. --src X --dst X skips both fast paths and rebuilds the container in place, contradicting the byte-for-byte promise for a patch-free copy. (The second reader refuted that the source is destroyed: RevitFile::open reads the whole file first.)
  • 7. The empty-patch fast path leaves .<dst>.copy-<pid> behind when the copy or the rename fails, against the module doc.

Changes

  • src/writer.rs: validate_patches (new, public) is what write_with_patches refuses before it writes: a missing stream, a framing the stream is not stored in (read from the stream's first bytes: gzip from byte 0, or eight bytes and then gzip; Verbatim is never checked), and a stored page. write_with_patches calls it. The path choice uses rvt::cli::same_file (fix(cli): the CLIs refuse to write over their input under any name, rvt-info writes a file's text as text in a CSV cell, rvt-dump escapes a stream's name, and rvt-ifc writes its IFC whole under --observation (#1885) #1891) in place of comparing the paths as typed: a patch-free write of a file onto itself returns without touching it, and the copy path removes its temporary file when the copy or the rename fails.
  • src/bin/rvt_write.rs: a dry run needs no manifest and calls validate_patches; a base64 value that decodes to nothing is refused with the way to say it on purpose ("new_decompressed": []); zero patches is a plain copy, not a verification failure; the source opened for the dry run is dropped before the write opens it.
  • tests/cli_ergonomics.rs: the end-to-end checks below. Fragment: changelog.d/fixed/1885-rvt-write-checks.md.

Not in this PR: items 12 to 14 of #1885 (rvt-dump memory and limits, the preview's PNG check, gen-fixture --name), which are not the write path.

Testing

Unit tests are banned in this repository; every check below is end to end on the tier-1 fixture, through the built rvt-write:

  • rvt_write_dry_run_needs_no_manifest_and_checks_what_the_write_would: a dry run with no manifest exits 0; a manifest naming a stream the file lacks, and one framing BasicFileInfo (stored as it stands, not as gzip) as RawGzipFromZero, exit 1 with the stream or not gzip-framed in the message, with --dry-run and without, and leave no file.
  • rvt_write_refuses_a_base64_value_that_empties_a_stream: "=" and "" exit 1 with decodes to no bytes and leave no file.
  • rvt_write_with_no_patch_copies_the_file_byte_for_byte_...: an empty manifest copies the file byte for byte and exits 0; the copy written onto itself, spelled two ways, is left as it was, with no dot-file temporary beside it.
  • CI's cli_real_files::write_round_trips_or_refuses_a_streams_own_bytes (Corpus health, the 12 family releases): Formats/Latest framed RawGzipFromZero and Global/Latest framed CustomPrefix8 are still written and read back, which is the check that the framing rule refuses nothing real. I cannot build locally (rule of this repository), so CI is the first compile of this change.

Audit-honesty checklist

  • README / docs reflect the current state after this PR (rvt-write --help is the doc of the dry run)
  • A user-visible change has its entry as a fragment under changelog.d/fixed/
  • N/A: no limitation resolved or introduced
  • Commit messages describe WHAT changed and WHY
  • No emojis in code, docs, or commit messages
  • No private paths, personal email addresses, or internal jargon in committed files
  • N/A: no reverse-engineering finding

Legal and contribution hygiene

  • I agree this work is licensable under Apache-2.0
  • This PR contains no Autodesk proprietary source, decompiled internals, or NDA'd SDK content
  • No new test fixtures

Breaking changes

rvt::writer::write_with_patches (and rvt-write) now return WriteRefused for a patch framed RawGzipFromZero or CustomPrefix8 over a stream stored otherwise. A caller that frames the bytes itself passes Verbatim, which is unchanged. The public item validate_patches is added.

Related issues

Refs #1885 (items 1 to 7; the issue stays open for items 12 to 14).

…vt-info writes a file's text as text in a CSV cell, rvt-dump escapes a stream's name, and rvt-ifc writes its IFC whole under --observation (#1885)

Items 8, 9, 10 and 11 of #1885, and the same-file half of its item 6's
neighbours, each fixed once where the CLIs share it:

- rvt::cli::same_file asks whether two paths are one file (resolved paths, or
  a hard link on Unix). rvt-gltf, rvt-sheet and rvt-schedule compared the
  output path with the input path as typed, so ./model.rvt and a link got
  through; rvt-ifc compared nothing, and rvt-ifc model.rvt -o model.rvt
  replaced the Revit file with the IFC. All four now check before they export.
- rvt::cli::csv_text is the one rule for a text cell: RFC 4180 quoting, and a
  leading ' where the text starts with = + - @ tab or CR. rvt-info -f csv put a
  title, a user name or a path of a crafted file into a cell as it stood, so a
  spreadsheet ran it as a formula. rvt-schedule's cells already had the rule,
  written out there; they take it from here too, with no change to their output.
- rvt-dump printed a stream's name as it stood, control characters included; it
  prints it escaped. The file name it writes to was already sanitised.
- rvt-ifc --observation wrote the IFC straight to the output's name, so a
  killed export left a truncated .ifc there. It is written beside the output
  and renamed when whole, as the export without --observation is.

End to end: the tier-1 fixture is given to rvt-gltf, rvt-sheet, rvt-schedule
and rvt-ifc with the output named ./model.rvt, through a symbolic link and
through a hard link, and every one refuses and leaves the file as it was;
rvt-info -f csv on a file named =1+1.rvt writes '=1+1.rvt in the path cell.
csv_text is a pure helper and has failure-first tests next to it.

Part of #1885 (its rvt-write items follow in their own change).
…a patch is refused that frames a stream otherwise than it is stored, and an empty or self-copying write is a plain copy (#1885)

Items 1 to 7 of #1885:

- validate_patches (new) is what write_with_patches refuses before it writes: a
  stream the file lacks (StreamNotFound), a framing the stream is not stored in
  and a patch that would span a checksummed page (WriteRefused). write_with_patches
  calls it, and so does rvt-write --dry-run, which needed --patches although its
  help says otherwise and exited 0 without looking at any stream.
- The manifest alone chose a stream's framing on disk, and verification read the
  stream back with the same framing, so a stream written in the wrong framing
  passed. A patch framed RawGzipFromZero or CustomPrefix8 is refused unless the
  stream is stored that way, read from its first bytes; Verbatim is the caller's
  own framing and is never checked.
- A base64 value that decodes to no bytes ("=", "") emptied the stream; it is
  refused, and the manifest says "new_decompressed": [] to mean it.
- An empty patches array wrote the copy and then exited 1 with "0 stream(s)
  failed verification"; it is a plain copy, as the writer already made it.
- One file under two names (a link, ./x) is one file: a write with no patch leaves
  it as it is, where it rebuilt the container in place, and the copy path removes
  its temporary file when the copy or the rename fails.

End to end, on the tier-1 fixture: a dry run with no manifest exits 0; a missing
stream and a wrong framing are refused by the dry run and by the write, and
leave no file; "=" and "" are refused; an empty manifest copies the file byte for
byte; the file onto itself, spelled two ways, is left as it was with no temporary
beside it. The real-file round trip of Formats/Latest and Global/Latest on the
twelve family releases (cli_real_files) is unchanged.

Part of #1885 (items 12 to 14 follow).
rvt-rs-review[bot]
rvt-rs-review Bot previously approved these changes Nov 13, 2026
The conflict was in tests/cli_ergonomics.rs, where both branches added tests at
the same place; both sets are kept. The result differs from main by this
branch's own four files. The changelog fragment now says the library's
write_with_patches refuses a mismatched framing.
@DrunkOnJava

Copy link
Copy Markdown
Owner Author

Approved at 49d928a by the review bot as a self-approval, under Griffin's answer of 2026-11-12 ("You are allowed to self-approve"): rvtDevelop's session has not read the head sent to it at about 11:40 UTC, and its earlier approval of this PR was dismissed by the push that merged main. I re-read the whole diff (writer.rs, rvt_write.rs, the tests) as if another session had written it; the push since that approval is the merge of main only.

@DrunkOnJava
DrunkOnJava merged commit a133f6e into main Nov 13, 2026
36 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/1885-rvt-write branch November 13, 2026 13:01
DrunkOnJava added a commit that referenced this pull request Nov 13, 2026
…a stream it cannot read, rvt-info refuses a preview that is not a whole PNG, and gen-fixture refuses a name with a path in it (#1885) (#1906)

## Summary

Items 12, 13 and 14 of #1885, the three that are neither the write path
(#1893) nor the CLIs' shared output rules (#1891, landed): `rvt-dump`
takes the resource-limit options and goes on past a stream it cannot
read, `rvt-info --extract-preview` refuses a preview that is not a whole
PNG, and `gen-fixture` refuses a name with a path in it. Part of #1885;
the issue closes when #1893 has landed too.

## Motivation

Batch 5's audit of the CLIs that write files (main at `e57db423`; each
finding confirmed by a second reader):
- **12.** `rvt-dump` opened every file under the default limits, so one
stream over 256 MiB stopped the whole dump with an error and no option
changed it (`rvt_dump.rs:59,72`); and it kept every inflated partition
in the reader's memo though it writes them one at a time
(`reader.rs:965-968`; the memo's budget is 16 GiB).
- **13.** `--extract-preview` wrote what the stream held from the PNG
signature on and said "preview PNG written", when a preview cut short
has no IEND chunk (`rvt_info.rs:156-159`).
- **14.** `gen-fixture NAME` with no `--output` wrote
`tests/fixtures/synthetic-NAME.rvt`, so `--name ../x` wrote outside the
folder (`gen_fixture.rs:161-164`). A developer tool and the user's own
argument; low.

## Changes

- `src/bin/rvt_dump.rs`: `--max-stream-bytes`, `--max-inflate-bytes`,
`--large-model` and `--allow-partial` as `rvt-gltf` has them
(`rvt::cli::open_limits`, `unread_stream_report`); a stream over the
limit prints "not read: over the stream limit" and the dump goes on; at
the end the reader's list of what a limit left unread goes to stderr and
the exit status is 3 unless `--allow-partial`. A partition is written
from the reader's shared buffer, not a copy, and
`RevitFile::release_inflated_partitions` (was `pub(crate)`, now `pub`)
runs after each stream.
- `src/bin/rvt_info.rs`: `ends_with_iend`; a preview without an IEND
chunk is not written, and the command exits 1 saying the preview is cut
short.
- `src/bin/gen_fixture.rs`: a name with `/` or `\` is refused when it
would become a file name under `tests/fixtures`.
- `tests/cli_ergonomics.rs` (three tests, appended), `src/reader.rs`
(the method's visibility and doc),
`changelog.d/fixed/1885-dump-preview-fixture.md`.

## Testing

Unit tests are banned in this repository; each check is end to end
through the built binaries, on a file `gen-fixture` makes:
- [x] `rvt_dump_lists_a_stream_over_the_limit_and_dumps_the_rest`: with
default limits the dump exits 0 with nothing on stderr; under
`--max-stream-bytes 100` it exits 3, lists `BasicFileInfo` as not read,
writes no file for it, dumps the preview stream after it, and reports
the unread streams and `--allow-partial` on stderr; with
`--allow-partial` it exits 0.
- [x] `extract_preview_writes_a_whole_png_and_refuses_one_cut_short`:
the fixture's preview comes out as a PNG ending in IEND; the same file
with its preview stream replaced by a PNG signature and half an IHDR
chunk exits 1, says "cut short" and writes nothing.
- [x] `gen_fixture_name_with_a_path_in_it_writes_nothing`: `../escape`,
`a/b` and `a\b` exit 1 with "path separator" and make no folder; `plain`
writes `tests/fixtures/synthetic-plain.rvt` under `CARGO_MANIFEST_DIR`.
- [x] This PR's CI (head d83987c, run 43418515306, every job green):
the three tests above pass on Linux, Windows and macOS. No export moves.

Not measured: the memory `rvt-dump` saves by dropping each partition
after it is written (no peak was recorded before or after; the saving is
by construction, one inflated partition at a time instead of all of
them).

## Audit-honesty checklist

- [x] README / docs reflect the current state after this PR (`rvt-dump
--help` and `rvt-info --help` are the docs of these options)
- [x] A user-visible change has its entry as a fragment under
`changelog.d/fixed/`
- N/A: no limitation resolved or introduced
- [x] Commit messages describe WHAT changed and WHY
- [x] No emojis in code, docs, or commit messages
- [x] No private paths, personal email addresses, or internal jargon in
committed files
- N/A: no reverse-engineering finding

## Legal and contribution hygiene

- [x] I agree this work is licensable under Apache-2.0
- [x] This PR contains no Autodesk proprietary source, decompiled
internals, or NDA'd SDK content
- [x] No new test fixtures

## Breaking changes

`rvt-dump` exits 3 where a resource limit left a stream unread (it used
to stop with exit 1 on a stream over the stream limit, and exit 0 on a
partition cut short by an inflate limit); `--allow-partial` restores 0.
`rvt-info --extract-preview` exits 1 for a preview cut short, where it
wrote the bytes. `RevitFile::release_inflated_partitions` is a new
public method.

## Related issues

Part of #1885 (items 12 to 14).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant