Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/lib_ccx/file_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,13 @@ int init_file_buffer(struct ccx_demuxer *ctx)
{
ctx->filebuffer_start = 0;
ctx->filebuffer_pos = 0;
// Called for every newly opened file. Whatever the buffer still holds
// belongs to the previous file and has been consumed; keeping its byte
// count while rewinding the position would replay it as new data.
ctx->bytesinbuffer = 0;
if (ctx->filebuffer == NULL)
{
ctx->filebuffer = (unsigned char *)malloc(FILEBUFFERSIZE);
ctx->bytesinbuffer = 0;
}
if (ctx->filebuffer == NULL)
{
Expand Down
10 changes: 7 additions & 3 deletions src/rust/src/demuxer/demux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,16 @@ mod tests {
let mut ctx = dummy_demuxer();
let buf = vec![1u8; unsafe { FILEBUFFERSIZE } as usize].into_boxed_slice();
ctx.filebuffer = Box::into_raw(buf) as *mut u8;
let original = ctx.filebuffer;
ctx.bytesinbuffer = 123;
ctx.filebuffer_pos = 123;
let res = init_file_buffer(&mut ctx);
assert_eq!(res, 0);
assert!(!ctx.filebuffer.is_null());
// bytesinbuffer remains unchanged.
assert_eq!(ctx.bytesinbuffer, 123);
assert_eq!(ctx.filebuffer, original);
// The bytes belong to the previously opened file: they must not be
// replayed as data of the new one.
assert_eq!(ctx.filebuffer_pos, 0);
assert_eq!(ctx.bytesinbuffer, 0);
// Clean up.
unsafe {
let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut(
Expand Down
5 changes: 4 additions & 1 deletion src/rust/src/file_functions/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ pub const FILEBUFFERSIZE: usize = 1024 * 1024 * 16; // 16 Mbytes no less. Minimi
pub fn init_file_buffer(ctx: &mut CcxDemuxer) -> i32 {
ctx.filebuffer_start = 0;
ctx.filebuffer_pos = 0;
// Called for every newly opened file. Whatever the buffer still holds
// belongs to the previous file and has been consumed; keeping its byte
// count while rewinding the position would replay it as new data.
ctx.bytesinbuffer = 0;
if ctx.filebuffer.is_null() {
let mut buf = vec![0u8; FILEBUFFERSIZE].into_boxed_slice();
ctx.filebuffer = buf.as_mut_ptr();
mem::forget(buf);
ctx.bytesinbuffer = 0;
}
if ctx.filebuffer.is_null() {
return -1;
Expand Down
Loading