Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/lib_ccx/avc_functions.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#ifndef AVC_FUNCTION_H
#define AVC_FUNCTION_H

#include <stdint.h>

struct avc_ctx
{
unsigned char cc_count;
uint16_t cc_count;
// buffer to hold cc data
unsigned char *cc_data;
int64_t cc_databufsize;
Expand Down
2 changes: 1 addition & 1 deletion src/rust/src/avc/common_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
pub cc_databufsize: usize,
pub cc_buffer_saved: bool,
Expand Down
16 changes: 15 additions & 1 deletion src/rust/src/avc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
}
}
Loading