mirror of
https://github.com/rustdesk/magnum-opus.git
synced 2026-10-26 05:50:16 +00:00
Fix Repacketizer soundness with proper lifetime bounds
RepacketizerState represents an in-progress repacketization with specific lifetime bounds on the input buffers.
This commit is contained in:
1 parent
f98c05957f
commit
3c6ce567f6
2 files changed
+72
-30
No files matched your search
@@ -64,3 +64,34 @@ fn encode_bad_buffer() {
|
||||
Err(err) => assert_eq!(err.code(), opus::ErrorCode::BadArg),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repacketizer() {
|
||||
let mut rp = opus::Repacketizer::new().unwrap();
|
||||
|
||||
for _ in 0..2 {
|
||||
let packets = &[
|
||||
&[249, 255, 254, 255, 254][..],
|
||||
&[248, 255, 254][..],
|
||||
];
|
||||
|
||||
let mut state = rp.begin();
|
||||
for &packet in packets {
|
||||
state.cat(packet).unwrap();
|
||||
}
|
||||
|
||||
let mut out = [0; 256];
|
||||
let len = state.out(&mut out).unwrap();
|
||||
assert_eq!(&out[..len], &[251, 3, 255, 254, 255, 254, 255, 254]);
|
||||
}
|
||||
|
||||
{
|
||||
let packet = [248, 255, 254];
|
||||
let state = rp.begin().cat_move(&packet).unwrap();
|
||||
let packet = [249, 255, 254, 255, 254];
|
||||
let state = state.cat_move(&packet).unwrap();
|
||||
let mut out = [0; 256];
|
||||
let len = {state}.out(&mut out).unwrap();
|
||||
assert_eq!(&out[..len], &[251, 3, 255, 254, 255, 254, 255, 254]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user