diff --git a/src/lib_ccx/avc_functions.h b/src/lib_ccx/avc_functions.h index e46ceae6d..2e3ca5dc6 100644 --- a/src/lib_ccx/avc_functions.h +++ b/src/lib_ccx/avc_functions.h @@ -1,9 +1,11 @@ #ifndef AVC_FUNCTION_H #define AVC_FUNCTION_H +#include + struct avc_ctx { - unsigned char cc_count; + uint16_t cc_count; // buffer to hold cc data unsigned char *cc_data; int64_t cc_databufsize; diff --git a/src/rust/src/avc/common_types.rs b/src/rust/src/avc/common_types.rs index 4fcb4e5ea..755099227 100644 --- a/src/rust/src/avc/common_types.rs +++ b/src/rust/src/avc/common_types.rs @@ -4,7 +4,7 @@ pub const MAXBFRAMES: i32 = 50; #[derive(Debug, Clone)] pub struct AvcContextRust { - pub cc_count: u8, + pub cc_count: u16, pub cc_data: Vec, pub cc_databufsize: usize, pub cc_buffer_saved: bool, diff --git a/src/rust/src/avc/core.rs b/src/rust/src/avc/core.rs index e4d68ab2b..3267bbd5e 100644 --- a/src/rust/src/avc/core.rs +++ b/src/rust/src/avc/core.rs @@ -442,7 +442,7 @@ pub fn copy_ccdata_to_buffer(ctx: &mut AvcContextRust, source: &[u8], new_cc_cou if start_idx + copy_len <= ctx.cc_data.len() { ctx.cc_data[start_idx..start_idx + copy_len].copy_from_slice(&source[..copy_len]); - ctx.cc_count += new_cc_count as u8; + ctx.cc_count += new_cc_count as u16; ctx.cc_buffer_saved = false; } } @@ -796,4 +796,18 @@ mod tests { let buf = [0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x65]; assert_eq!(find_nal_start_code(&buf), Some(5)); } + + #[test] + fn test_copy_ccdata_to_buffer_beyond_u8_max() { + let mut ctx = AvcContextRust::default(); + ctx.cc_data = vec![0u8; 1024]; + ctx.cc_databufsize = 1024; + ctx.cc_count = 250; + + let dummy_source = vec![0xFA; 64]; // 20 triplets = 60 + 1 = 61 bytes + copy_ccdata_to_buffer(&mut ctx, &dummy_source, 20); + + // 250 + 20 = 270 triplets. If it were u8, it would wrap to 14. + assert_eq!(ctx.cc_count, 270); + } }