From 6b4359f4ae8be8d67e1347f9b304cdf6a0c8542c Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 23 May 2022 22:00:45 +0300 Subject: [PATCH] [mod_av] Avoid using 16384 stack (or heap) bytes in av_file_write(). Remove ff_input_buffer_padding static variable. --- src/mod/applications/mod_av/avcodec.c | 7 ++----- src/mod/applications/mod_av/avformat.c | 5 ++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/mod/applications/mod_av/avcodec.c b/src/mod/applications/mod_av/avcodec.c index 703dc1b2ce..a9f6d0927e 100644 --- a/src/mod/applications/mod_av/avcodec.c +++ b/src/mod/applications/mod_av/avcodec.c @@ -405,8 +405,6 @@ typedef struct h264_codec_context_s { #define AV_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE #endif -static uint8_t ff_input_buffer_padding[AV_INPUT_BUFFER_PADDING_SIZE] = { 0 }; - #define MAX_PROFILES 100 typedef struct avcodec_profile_s { @@ -753,8 +751,7 @@ static switch_status_t buffer_h263_rfc4629_packets(h264_codec_context_t *context if (len < 0) return SWITCH_STATUS_FALSE; if (startcode) { - uint8_t zeros[2] = { 0 }; - switch_buffer_write(context->nalu_buffer, zeros, 2); + switch_buffer_zero_fill(context->nalu_buffer, 2); } switch_buffer_write(context->nalu_buffer, data, len); @@ -1712,7 +1709,7 @@ static switch_status_t switch_h264_decode(switch_codec_t *codec, switch_frame_t if (size > 0) { av_init_packet(&pkt); - switch_buffer_write(context->nalu_buffer, ff_input_buffer_padding, sizeof(ff_input_buffer_padding)); + switch_buffer_zero_fill(context->nalu_buffer, AV_INPUT_BUFFER_PADDING_SIZE); switch_buffer_peek_zerocopy(context->nalu_buffer, (const void **)&pkt.data); pkt.size = size; diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index f748968202..1f5e7e5f0e 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -2043,7 +2043,7 @@ static switch_status_t av_file_write(switch_file_handle_t *handle, void *data, s int lead_frames = (context->offset * fps) / 1000; for (int x = 0; x < lead_frames; x++) { - switch_buffer_write(context->audio_buffer, buf, datalen); + switch_buffer_zero_fill(context->audio_buffer, datalen); } context->offset = 0; } @@ -2063,8 +2063,7 @@ GCC_DIAG_ON(deprecated-declarations) if (context->closed) { inuse = switch_buffer_inuse(context->audio_buffer); if (inuse < bytes) { - char buf[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0}; - switch_buffer_write(context->audio_buffer, buf, bytes - inuse); + switch_buffer_zero_fill(context->audio_buffer, bytes - inuse); } }