]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_av] Avoid using 16384 stack (or heap) bytes in av_file_write(). Remove ff_input_... 1666/head
authorAndrey Volk <andywolk@gmail.com>
Mon, 23 May 2022 19:00:45 +0000 (22:00 +0300)
committerAndrey Volk <andywolk@gmail.com>
Mon, 23 May 2022 19:00:45 +0000 (22:00 +0300)
src/mod/applications/mod_av/avcodec.c
src/mod/applications/mod_av/avformat.c

index 703dc1b2ce3f4e6fbdecfb10739a9252e9bbd4c1..a9f6d0927e0296fe2de0fcc89234c0b156337af6 100644 (file)
@@ -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;
 
index f7489682028b82e63835b2b77864f35972a94a94..1f5e7e5f0ed894a8171af07969508f01ea6fad43 100644 (file)
@@ -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);
                }
        }