Skip to content

file_store: oversized entry length prefix panics Store::load instead of returning an error #2306

Description

@noahjoeris

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:

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::<BTreeSet<String>>::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.

Activity

  1. Brijesh-Thakkar commented on Sep 30, 2026

    @Brijesh-Thakkar

    I would love to work on this issue
    will raise PR for this one

  2. Brijesh-Thakkar commented on Sep 30, 2026

    @Brijesh-Thakkar

    I'm not opening a separate fix. #2258 already handles this, and I've left the verification details in a comment there.

  3. moved this from Todo to In Progress in BDK Chainon Oct 8, 2026
  4. luhrhenz commented on Oct 8, 2026

    @luhrhenz

    created a pr to fix this issue..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    • Status
      In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions