Skip to content

export(updates_in_range) panics with several non-contiguous spans of one peer #1155

Closed

Description

@zxch3n

Summary

LoroDoc::export(ExportMode::updates_in_range(spans)) panics with counter should be continuous (crates/loro-internal/src/oplog/change_store.rs:1000, ChangeStore::insert_change_inner, reached via export_blocks_in_range) when spans holds two or more non-contiguous spans of the same peer. The panic happens while the oplog lock is held, so the doc is poisoned afterwards (and in WASM the instance traps).

Found during the adversarial review of #1125. Not caused by #1125, and not fixed there.

Minimal repro (main 1eb14b3b)

use loro::{ExportMode, IdSpan, LoroDoc};

let doc = LoroDoc::new();
doc.set_peer_id(1).unwrap();
let text = doc.get_text("t");
for i in 0..10 {
    text.insert(i, "a").unwrap();
    doc.commit();
}
// panics: counter should be continuous
doc.export(ExportMode::updates_in_range(vec![
    IdSpan::new(1, 0, 2),
    IdSpan::new(1, 5, 7),
]));

Expected

Either export both ranges, or return Err for spans the export cannot represent. It should not panic.

Notes

A single span, or spans of different peers, work. The export path inserts the selected changes into a temporary change store, and that store requires each peer's counters to be contiguous.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions