file_store: `Store::load` never terminates when a changeset entry decodes to zero bytes

Aperta Adatta ai principianti
#2,307 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
databases

Direzione di ricerca

Inizia da crates/file_store/src/entry_iter.rs, in particolare da EntryIter::next e dal relativo ciclo di deserializzazione. Aggiungi o usa crates/file_store/tests/test_zero_width.rs, quindi esegui cargo test -p bdk_file_store --test test_zero_width. Il lavoro è completato quando Store::load termina per un changeset di larghezza zero seguito da un byte finale e restituisce il changeset oppure un errore.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Describe the bug

EntryIter::next (crates/file_store/src/entry_iter.rs) treats every successful deserialize_from as progress but never checks that the read advanced the file offset. For a changeset type whose bincode encoding is zero bytes (e.g. (), which implements Merge in bdk_core), any trailing byte after the magic bytes makes Store::dump decode the same position over and over, so Store::load never returns.

This affects loading a corrupted or hand-edited store file. #2258 appears to address this by framing each entry with a length prefix.

This issue was found by AI.

To Reproduce

Add crates/file_store/tests/test_zero_width.rs and run cargo test -p bdk_file_store --test test_zero_width:

use bdk_file_store::Store;
use std::time::Duration;

const MAGIC: &[u8] = b"bdk_test_magic";

#[test]
fn load_terminates_on_zero_width_changeset() {
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("db");
    let mut bytes = MAGIC.to_vec();
    bytes.push(0xff); // any trailing byte
    std::fs::write(&path, &bytes).unwrap();

    let (tx, rx) = std::sync::mpsc::channel();
    std::thread::spawn(move || {
        let result = Store::<()>::load(MAGIC, &path);
        let _ = tx.send(result.is_ok());
    });
    // `()` decodes as zero bytes, so the file offset never advances and `load` never reaches EOF.
    assert!(
        rx.recv_timeout(Duration::from_secs(5)).is_ok(),
        "load did not terminate"
    );
}

Current output:

thread 'load_terminates_on_zero_width_changeset' panicked at crates/file_store/tests/test_zero_width.rs:20:5:
load did not terminate

Expected behavior

Loading a store file should always terminate, returning either the aggregated changeset or an error.

Lingua principale
Rust
Stelle
1.1k
Fork
491
Merge medio
1g 5h
PR unite (30g)
1

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bitcoindevkit/bdk

Tutte le issue di bitcoindevkit/bdk

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.