bitcoindevkit / bitcoindevkit/bdk
file_store: oversized entry length prefix panics `Store::load` instead of returning an error
- Dominant language
- Rust
- Stars
- 1.1k
- Forks
- 483
- Avg merge
- 20d 3h
- Merged PRs (30d)
- 3
Description
**Describe the bug**
`EntryIter::next` decodes each entry with `bincode_options().deserialize_from(..)`, and `bincode_options()` (`crates/file_store/src/lib.rs`) sets no size limit. A length prefix read from the file is therefore passed straight to the buffer allocation. An entry declaring a `String` length of `u64::MAX` panics with `capacity overflow` inside `Store::load`; smaller but still oversized lengths attempt a huge allocation instead of returning `StoreError::Bincode`.
This affects loading a corrupted or hand-edited store file. #2258 appears to address this by bounding the frame allocation.
This issue was found by AI.
**To Reproduce**
Add `crates/file_store/tests/test_oversized_len.rs` and run `cargo test -p bdk_file_store --test test_oversized_len`:
```rust
use bdk_file_store::Store;
use std::collections::BTreeSet;
const MAGIC: &[u8] = b"bdk_test_magic";
#[test]
fn load_returns_error_on_oversized_length_prefix() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("db");
let mut bytes = MAGIC.to_vec();
bytes.push(1); // BTreeSet length: 1 element
bytes.push(253); // bincode varint tag: u64 follows
bytes.extend_from_slice(&u64::MAX.to_le_bytes()); // String length: u64::MAX
std::fs::write(&path, &bytes).unwrap();
let result = Store::>::load(MAGIC, &path);
assert!(result.is_err(), "load should fail with an error, not panic");
}
```
Current output:
```
thread 'load_returns_error_on_oversized_length_prefix' panicked at library/alloc/src/raw_vec/mod.rs:28:5:
capacity overflow
```
**Expected behavior**
Loading a store file whose entry declares a length that cannot be satisfied should return an error rather than panic or attempt an unbounded allocation.
Contributor guide
Research direction
Start with bincode_options() in crates/file_store/src/lib.rs and the EntryIter::next path used by Store::load. Run cargo test -p bdk_file_store --test test_oversized_len using the reproduction in crates/file_store/tests/test_oversized_len.rs. Done means an oversized length prefix returns an error without panicking or attempting an unbounded allocation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100