diff mbox series

[FFmpeg-devel,1/2] avcodec/ac3enc: Use actual size of buffer in init_put_bits()

Message ID HE1PR0301MB21546392CB0D0FEC53FD19768F7E9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 968c158abde36ebb7520706a69eebe3e8eacbd81
Headers show
Series [FFmpeg-devel,1/2] avcodec/ac3enc: Use actual size of buffer in init_put_bits() | expand


Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 29, 2021, 5:08 p.m. UTC
Since the very beginning (since de6d9b6404bfd1c589799142da5a95428f146edd)
the AC-3 encoder used AC3_MAX_CODED_FRAME_SIZE (namely 3840) for the
size of the output buffer (without any check at all).
This causes problems when encoding EAC-3 for which the maximum is too small,
smaller than the actual size of the buffer: One can run into asserts used
by the PutBits API. Ticket #8513 is about such a case and this commit
fixes it by using the real size of the buffer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Not checking the size of the output buffer seems to have been wrong
when it was added; yet commit 0ecca7a49f8e254c12a3a1de048d738bfbb614c6
added a FF_MIN_BUFFER_SIZE of 16384, thereby legitimizing this
behaviour. This number (renamed to AV_INPUT_BUFFER_MIN_SIZE) still
exists and it is used by a few encoders, yet not by any allocation
function at all. It seems to me that there is no reason why this
constant should be public (if it should exist at all).

 libavcodec/ac3.h    | 1 -
 libavcodec/ac3enc.c | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)
diff mbox series


diff --git a/libavcodec/ac3.h b/libavcodec/ac3.h
index f8f6a81f45..e358f8d9e3 100644
--- a/libavcodec/ac3.h
+++ b/libavcodec/ac3.h
@@ -27,7 +27,6 @@ 
 #ifndef AVCODEC_AC3_H
 #define AVCODEC_AC3_H
-#define AC3_MAX_CODED_FRAME_SIZE 3840 /* in bytes */
 #define EAC3_MAX_CHANNELS 16          /**< maximum number of channels in EAC3 */
 #define AC3_MAX_CHANNELS 7            /**< maximum number of channels, including coupling channel */
 #define CPL_CH 0                      /**< coupling channel index */
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 8044e6dcd0..4cfd0afe12 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -1729,7 +1729,7 @@  static void ac3_output_frame(AC3EncodeContext *s, unsigned char *frame)
     int blk;
-    init_put_bits(&s->pb, frame, AC3_MAX_CODED_FRAME_SIZE);
+    init_put_bits(&s->pb, frame, s->frame_size);