Skip to content

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

Merged
DrunkOnJava merged 1 commit into
mainfrom
fix/1885-cli-output-hygiene
Nov 13, 2026

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Items 8, 9, 10 and 11 of #1885, each fixed once where the CLIs share it: no CLI writes over its input however the input is named, rvt-info's CSV cells and rvt-schedule's come from one rule that stops a file's text running as a formula, rvt-dump prints a stream's name escaped, and rvt-ifc --observation writes its IFC whole. The rvt-write items (1 to 7) follow in their own change. Part of #1885.

Motivation

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

  • 9. rvt-ifc model.rvt -o model.rvt replaced the Revit file with the IFC: nothing compared the output with the input. rvt-gltf, rvt-sheet and rvt-schedule compared the two paths as typed, so ./model.rvt, a symbolic link to it and (on Unix) a hard link got through.
  • 8. csv_field in rvt-info quotes commas and quotes and nothing else, so a title, a user name or a path from a crafted file that starts with =, +, - or @ runs as a formula when its CSV is opened. rvt-schedule's cells have had the rule for a while, written out in schedule_csv.rs.
  • 10. With --observation, rvt-ifc wrote its IFC straight to the output's name, so a killed export left a truncated .ifc under it; without --observation it is written beside the output and renamed.
  • 11. rvt-dump printed a stream's name as it stood, so control characters in a crafted name reached the terminal.

Changes

  • src/cli.rs: same_file (resolved paths, or one inode on Unix) and csv_text (RFC 4180 quoting, and a leading ' where the text starts with =, +, -, @, a tab or a carriage return), with failure-first unit tests for the pure csv_text.
  • rvt-gltf, rvt-sheet, rvt-schedule: the input-as-output check is same_file. rvt-ifc: the same check, before the export (which can take minutes), and write_whole for the --observation run's IFC.
  • rvt-info: every CSV cell goes through csv_text. src/ifc/schedule_csv.rs: its text is csv_text, the same rule with the same output.
  • rvt-dump: the name in each line is escape_debugged.
  • tests/cli_ergonomics.rs, tests/rvt_info_cli.rs: the end-to-end checks below. Fragments: changelog.d/fixed/1885-output-over-input.md, changelog.d/security/1885-csv-cells-and-stream-names.md.

Testing

Unit tests are banned in this repository except for pure helpers; csv_text is one (no I/O), and its five tests are the ways it can fail: each leading character, a carriage return that is both led and quoted, a formula that also holds commas and quotes, text that must not change, and plain quoting. Everything that touches a file is tested end to end:

  • refuses_to_overwrite_the_input_however_it_is_spelled: the tier-1 fixture is given to rvt-gltf, rvt-sheet, rvt-schedule and rvt-ifc with the output named dir/./model.rvt, through a symbolic link and through a hard link; every run exits 1 with refusing to overwrite the input and the file is byte for byte as it was. Passed in the full CI on e145ff1 on Linux, Windows and macOS.
  • csv_inventory_does_not_let_a_file_name_run_as_a_formula: rvt-info -f csv on a file named =1+1.rvt writes '=1+1.rvt, in the path cell. Passed on the same three.
  • This PR's CI (build and test on Linux, macOS and Windows; clippy; the real-file and CLI targets). No export moves: schedule_csv's cell rule is the same text through the shared function, and Measure's CSV outputs are unchanged by construction. I cannot build locally (rule of this repository), so CI is the first compile of this change. Full CI passed on e145ff1. Measure 43410992623 (head e145ff1, scorers from main): exports 146 of 146 identical, diagnostics 121 of 121 identical, same-project gates pass.

Audit-honesty checklist

  • README / docs reflect the current state after this PR (no doc says an rvt-info CSV cell is raw)
  • A user-visible change has its entry as a fragment under changelog.d/ (fixed and security)
  • 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 (the tier-1 fixture is copied to a scratch folder)

Breaking changes

rvt-info -f csv cells that start with =, +, - or @ now start with ' (a path or title; the numeric columns are non-negative integers). A script that read such a cell back sees the extra character.

Related issues

Refs #1885 (items 8 to 11; the issue stays open for the rvt-write items and 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).
@DrunkOnJava
DrunkOnJava merged commit 0c58ea6 into main Nov 13, 2026
38 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/1885-cli-output-hygiene branch November 13, 2026 11:18
DrunkOnJava added a commit that referenced this pull request 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 added a commit that referenced this pull request Nov 13, 2026
…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)

## 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` (#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

- [x] README / docs reflect the current state after this PR (`rvt-write
--help` is the doc of the dry run)
- [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::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).
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