Skip to content

Commit 5572fb9

Browse files
committed
ffi: Initialize AVIF output structs to defaults before populating.
Matches the pattern used by all other FFI getters, ensuring C callers always see valid (zeroed) fields even on error paths.
1 parent c13997b commit 5572fb9

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

mp4parse/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3815,8 +3815,10 @@ fn read_colr<T: Read>(
38153815
/// Rotation in the positive (that is, anticlockwise) direction
38163816
/// Visualized in terms of starting with (⥠) UPWARDS HARPOON WITH BARB LEFT FROM BAR
38173817
/// similar to a DIGIT ONE (1)
3818+
#[derive(Default)]
38183819
pub enum ImageRotation {
38193820
/// ⥠ UPWARDS HARPOON WITH BARB LEFT FROM BAR
3821+
#[default]
38203822
D0,
38213823
/// ⥞ LEFTWARDS HARPOON WITH BARB DOWN FROM BAR
38223824
D90,

mp4parse_capi/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub enum Mp4parseAvifLoopMode {
341341
}
342342

343343
#[repr(C)]
344-
#[derive(Debug)]
344+
#[derive(Debug, Default)]
345345
pub struct Mp4parseAvifInfo {
346346
pub premultiplied_alpha: bool,
347347
pub major_brand: [u8; 4],
@@ -383,7 +383,7 @@ pub struct Mp4parseAvifInfo {
383383
}
384384

385385
#[repr(C)]
386-
#[derive(Debug)]
386+
#[derive(Debug, Default)]
387387
pub struct Mp4parseAvifImage {
388388
pub primary_image: Mp4parseByteData,
389389
/// If no alpha item exists, members' `.length` will be 0 and `.data` will be null
@@ -1170,6 +1170,9 @@ pub unsafe extern "C" fn mp4parse_avif_get_info(
11701170
return Mp4parseStatus::BadArg;
11711171
}
11721172

1173+
// Initialize fields to default values to ensure all fields are always valid.
1174+
*avif_info = Default::default();
1175+
11731176
if let Ok(info) = mp4parse_avif_get_info_safe((*parser).context()) {
11741177
*avif_info = info;
11751178
Mp4parseStatus::Ok
@@ -1352,6 +1355,9 @@ pub unsafe extern "C" fn mp4parse_avif_get_image(
13521355
return Mp4parseStatus::BadArg;
13531356
}
13541357

1358+
// Initialize fields to default values to ensure all fields are always valid.
1359+
*avif_image = Default::default();
1360+
13551361
if let Ok(image) = mp4parse_avif_get_image_safe(&*parser) {
13561362
*avif_image = image;
13571363
Mp4parseStatus::Ok

0 commit comments

Comments
 (0)