Currently, calling KeyProvider::set_key or get_key with an out-of-range index causes a SIGABRT crash in the underlying native layer. Additionally, setting a key_ring_size over 255 silently fails to allocate the ring size it appears, leading to unexpected aborts later on.
Because both methods return failure types (bool and Option<Vec>), they should return a failure result rather than crashing the whole process. Remote peers can send bad indices in MSC4195 which creates a crash vector.
Proposed Fix / Expected Behavior
- Bounds-check at the FFI boundary: return false (set_key) or None (get_key) instead of asserting.
- Honor key_ring_size limits or clamp/reject values over the native cap.
- Document valid index ranges.
Environment
- livekit 0.7.48
- libwebrtc 0.3.38
- Linux x86_64 (not platform-specific; the assertion is in the native layer)
Repro
// 1. Index out of bounds causes SIGABRT
let kp = KeyProvider::new(KeyProviderOptions { key_ring_size: 16, ..Default::default() });
kp.set_key(&id, 16, vec![0u8; 32]);
// 2. Ring size > 255 allowed at init, but crashes later
let kp = KeyProvider::new(KeyProviderOptions { key_ring_size: 512, ..Default::default() });
kp.set_key(&id, 300, vec![0u8; 32]);
Prior downstream workaround reference (rejecting out-of-range indices before the FFI call): BillCarsonFr/matrix-rust-rtc#7
Currently, calling KeyProvider::set_key or get_key with an out-of-range index causes a SIGABRT crash in the underlying native layer. Additionally, setting a key_ring_size over 255 silently fails to allocate the ring size it appears, leading to unexpected aborts later on.
Because both methods return failure types (bool and Option<Vec>), they should return a failure result rather than crashing the whole process. Remote peers can send bad indices in MSC4195 which creates a crash vector.
Proposed Fix / Expected Behavior
Environment
Repro
Prior downstream workaround reference (rejecting out-of-range indices before the FFI call): BillCarsonFr/matrix-rust-rtc#7