clockworklabs / clockworklabs/SpacetimeDB

Panic in BSATN Deserializer via Invalid Type Reference

Open
#4,001 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
25.2k
Forks
1.1k
Avg merge
2d 7h
Merged PRs (30d)
46

Description

AlgebraicTypeRef is a u32 index read directly from input. When resolving type references, no bounds check is performed before indexing into the Typespace.

use spacetimedb_sats::{bsatn, AlgebraicType, AlgebraicValue};

  fn main() {
      // BSATN-encoded AlgebraicType::Ref(0)
      let type_bytes: &[u8] = &[0x00, 0x00, 0x00, 0x00, 0x00];
      let ty: AlgebraicType = bsatn::from_slice(type_bytes).unwrap();

      // Panics: "index out of bounds: the len is 0 but the index is 0"
      let _ = AlgebraicValue::decode(&ty, &mut &[0u8; 8][..]);
  }

Stack Trace

0: rust_begin_unwind
1: core::panicking::panic_fmt
2: core::panicking::panic_bounds_check
3: <spacetimedb_sats::typespace::Typespace as core::ops::index::Index>::index
4: spacetimedb_sats:🇩🇪:impls::<impl DeserializeSeed for WithTypespace>::deserialize

Impact

  • Denial of Service if any code path deserializes AlgebraicType from untrusted input

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with spacetimedb_sats::typespace and the WithTypespace deserializer named in the stack trace, then reproduce the panic using the provided BSATN bytes. Trace invalid AlgebraicTypeRef resolution and add a regression test showing that an out-of-bounds reference returns an error instead of panicking.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.