Skip to content

Do not panic in Drop#13

Open
sbans-ff wants to merge 2 commits into
pka:mainfrom
freefly-systems:fix/no-panic-in-drop
Open

Do not panic in Drop#13
sbans-ff wants to merge 2 commits into
pka:mainfrom
freefly-systems:fix/no-panic-in-drop

Conversation

@sbans-ff

@sbans-ff sbans-ff commented Jun 9, 2026

Copy link
Copy Markdown

CopcWriter::drop calls self.close().expect(...). is_closed is only set on a successful close(), so two reachable paths panic on drop:

  • a writer constructed but never written — close() returns Err(EmptyCopcFile);
  • a write that errored before close() completed.

A panic in Drop while another panic is unwinding aborts the process, so this is a latent crash. This makes Drop a best-effort close that ignores the error; callers that need to observe close errors should finish the write explicitly rather than rely on Drop. Adds tests/drop_does_not_panic.rs (panics before the fix, clean after).


Stacked on #12 — the crate doesn't build against current las without that fix, so this branch includes its one commit. Happy to rebase to a single commit once #12 merges.

sbans-ff added 2 commits June 9, 2026 11:59
A fresh dependency resolution of copc-rs 0.5.0 selects las 0.9.11, which uses
laz 0.12 internally. copc-rs pins laz 0.9, so `header.laz_vlr()` returns a
laz-0.12 `LazVlr` while the compressor expects a laz-0.9 `LazVlr`:

    error[E0308] --> src/writer.rs:359:52
    expected `LazVlr`, found `laz::laszip::vlr::LazVlr`

So the crate does not compile for downstream consumers (which ignore the
committed lockfile) or after `cargo update`. Bump laz to 0.12 to unify on a
single laz shared with las; every laz API copc-rs uses is unchanged across
0.9 -> 0.12 (LazVlrBuilder, LazItemRecordBuilder, LazItemType, LazVlr consts,
record compressor/decompressor traits, ChunkTable).

Adds tests/roundtrip.rs (the crate had no tests): write -> read-back through
copc-rs's own writer/reader. It fails to *build* before the bump and passes
after, guarding against the dependency regressing again.
CopcWriter::drop called self.close().expect(...). is_closed is only set on a
successful close(), so two reachable paths panic on drop:

  * a writer constructed but never written (close() -> Err(EmptyCopcFile)), and
  * a write that errored before close() completed.

A panic in Drop while another panic is unwinding aborts the process. Make Drop a
best-effort close that ignores the error; callers needing to observe close errors
should finish the write explicitly. Adds tests/drop_does_not_panic.rs.
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