Thread 'main' panicked at 'index 252645158 out of range for slice of length 408',

Flatbuffer version : Latest rust
OS : Ubuntu 14 trusty
RUST : 1.17

Hi. I have modified a rust sample code given by a library 'Flatbuffers'. I get this error while trying to access any value present in the schema.

Encoding time: Duration { secs: 0, nanos: 56645 } // Encoding is successful
thread 'main' panicked at 'index 252645158 out of range for slice of length 408', /checkout/src/libcore/
note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.
stack backtrace:

0: core::slice::slice_index_len_fail
at /checkout/src/libcore/
1: <core::ops::Range as core::slice::SliceIndex>::index
at /checkout/src/libcore/
2: core::slice::<impl core::ops::Index for [T]>::index
at /checkout/src/libcore/
3: flatbuffers::endian_scalar::read_scalar_at
at flatbuffers/rust/flatbuffers/src/
4: flatbuffers::vtable::VTable::num_bytes
at flatbuffers/rust/flatbuffers/src/
5: flatbuffers::vtable::VTable::get
at flatbuffers/rust/flatbuffers/src/
6: flatbuffers::table::Table::get
at flatbuffers/rust/flatbuffers/src/
7: individual_messages::initial_ue_message_generated::InitialUEMessage::procedure_code
at ./src/
8: individual_messages::main
at ./src/

Apparently it cannot access the index. I am assuming that the buf or message that i received in encoded form is of length 408. I am sure that this has to do with the rust version as this error does not persist on the latest version.

I checked a related issue Rust panics if index out of bounds · Issue #28230 · rust-lang/rust · GitHub

So my question is how can i debug this?

please note that updating to the latest rust is not an option for me.

The panic doesn't look like a bug in Rust, or even a old-rust-specific issue. It's a standard behavior you get every time you use [x] with an invalid x.

Look through the stack trace, find where your code is, and review whether you're passing the right arguments. You can add assert!() or debug_assert!() to check things individually. For example, ensure you're not passing negative numbers to slice indexing (or subtracting too much from unsigned numbers).

If you're comfortable with debuggers, set a breakpoint on rust_panic and inspect the program from there.

When I see a strange number like that, I always try converting to hex.

Seems that number is 0x0f0f0f0f + 0x17. Suggests to me that an array of 0000111100001111... been cast to a u32, offset by 0x17 (23), and used as an index.

1 Like