file_store: `Store::load` never terminates when a changeset entry decodes to zero bytes
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 84/100
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
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di bitcoindevkit/bdk
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
bitcoindevkit/bdk#2309 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
bitcoindevkit/bdk#2308 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
bitcoindevkit/bdk#2294 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
bitcoindevkit/bdk#2293 ·
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
bitcoindevkit/bdk#2287 ·
Tutte le issue di bitcoindevkit/bdk
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
gitbutlerapp/gitbutler#15998 · 1 commento ·
-
bug triage:deciding
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
open-telemetry/otel-arrow#4132 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100