diff options
author | jstebbins <[email protected]> | 2012-05-01 07:55:41 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2012-05-01 07:55:41 +0000 |
commit | 4dcf3fcfd9aaeca7fe7ec06ff8c0c6b2d5d3c198 (patch) | |
tree | 3a6f82033c38c0f3115fb18547e048f478eb4a01 | |
parent | 356045a1bf9dc82e108a8832674d623be17b6338 (diff) |
libhb: allow arbitrary number of preview images, fixes potential crash
scan.c had a limit of 30 previews due to fixed array size. But test.c didn't
limit the max number of previews, so it was possible to generate a crash
by specifying > 30. This removes the limitation.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4616 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/scan.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/libhb/scan.c b/libhb/scan.c index a3e6e1832..ad9556528 100644 --- a/libhb/scan.c +++ b/libhb/scan.c @@ -9,8 +9,6 @@ #include "a52dec/a52.h" #include "dca.h" -#define HB_MAX_PREVIEWS 30 // 30 previews = every 5 minutes of a 2.5 hour video - typedef struct { hb_handle_t * h; @@ -403,12 +401,33 @@ static int column_all_dark( hb_work_info_t *info, uint8_t* luma, int top, int bo typedef struct { int n; - int t[HB_MAX_PREVIEWS]; - int b[HB_MAX_PREVIEWS]; - int l[HB_MAX_PREVIEWS]; - int r[HB_MAX_PREVIEWS]; + int *t; + int *b; + int *l; + int *r; } crop_record_t; +static crop_record_t * crop_record_init( int max_previews ) +{ + crop_record_t *crops = calloc( 1, sizeof(*crops) ); + + crops->t = calloc( max_previews, sizeof(int) ); + crops->b = calloc( max_previews, sizeof(int) ); + crops->l = calloc( max_previews, sizeof(int) ); + crops->r = calloc( max_previews, sizeof(int) ); + + return crops; +} + +static void crop_record_free( crop_record_t *crops ) +{ + free( crops->t ); + free( crops->b ); + free( crops->l ); + free( crops->r ); + free( crops ); +} + static void record_crop( crop_record_t *crops, int t, int b, int l, int r ) { crops->t[crops->n] = t; @@ -509,7 +528,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title ) int doubled_frame_count = 0; int interlaced_preview_count = 0; info_list_t * info_list = calloc( data->preview_count+1, sizeof(*info_list) ); - crop_record_t *crops = calloc( 1, sizeof(*crops) ); + crop_record_t *crops = crop_record_init( data->preview_count ); list_es = hb_list_init(); @@ -558,7 +577,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title ) if ( *data->die ) { free( info_list ); - free( crops ); + crop_record_free( crops ); return 0; } if (data->bd) @@ -932,7 +951,7 @@ skip_preview: title->detected_interlacing = 0; } } - free( crops ); + crop_record_free( crops ); free( info_list ); while( ( buf_es = hb_list_item( list_es, 0 ) ) ) |