From 2e9968cc79e61abc1d175e102efcd0d61ce3e4e8 Mon Sep 17 00:00:00 2001 From: Shank Date: Sun, 18 Dec 2022 14:18:10 -0500 Subject: [PATCH 1/2] add checks for swr_alloc() and av_malloc() results --- src/scan.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/scan.c b/src/scan.c index 85b36b3..63b3448 100644 --- a/src/scan.c +++ b/src/scan.c @@ -199,6 +199,9 @@ int scan_file(const char *file, unsigned index) { packet.size = buffer_size; swr = swr_alloc(); + if (swr == NULL){ + fail_printf("unable to allocate memory fro SwrContext"); + } *ebur128 = ebur128_init( ctx -> channels, ctx -> sample_rate, @@ -438,6 +441,9 @@ static void scan_frame(ebur128_state *ebur128, AVFrame *frame, ); out_data = av_malloc(out_size); + if (out_data == NULL){ + fail_printf("av_malloc failed to allocate memory"); + } if (swr_convert( swr, (uint8_t**) &out_data, frame -> nb_samples, From d2695a280cd47bf90d8b8f8a71ee2c17dd8c5744 Mon Sep 17 00:00:00 2001 From: Shank Date: Sun, 18 Dec 2022 14:20:19 -0500 Subject: [PATCH 2/2] return early if av_samples_get_buffer_size() returns a negative value --- src/scan.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/scan.c b/src/scan.c index 63b3448..feff3d6 100644 --- a/src/scan.c +++ b/src/scan.c @@ -439,6 +439,9 @@ static void scan_frame(ebur128_state *ebur128, AVFrame *frame, out_size = av_samples_get_buffer_size( &out_linesize, frame -> channels, frame -> nb_samples, out_fmt, 0 ); + if (out_size < 0){ + fail_printf("av_samples_get_buffer_size() failed with return code %d", out_size); + } out_data = av_malloc(out_size); if (out_data == NULL){