[FFmpeg-devel] [PATCH v2 10/10] avcodec/aptxenc: Process data in complete blocks of four samples only

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Tue Aug 31 15:42:58 EEST 2021


Otherwise one could read into the frame's padding when one encounters
the small last frame; furthermore, one would indicate a packet size
that is not a multiple of the actual block size and one would write
into the padding of said packet.

This actually happened in our FATE tests (where the number of samples
is 2 mod 4), which therefore needed to be updated.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/aptxenc.c   | 5 +++--
 tests/ref/fate/aptx    | 4 ++--
 tests/ref/fate/aptx-hd | 4 ++--
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavcodec/aptxenc.c b/libavcodec/aptxenc.c
index 5ea6053c26..0760d1932e 100644
--- a/libavcodec/aptxenc.c
+++ b/libavcodec/aptxenc.c
@@ -215,7 +215,7 @@ static int aptx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)
         return ret;
 
-    output_size = s->block_size * frame->nb_samples/4;
+    output_size = s->block_size * (frame->nb_samples/4);
     if ((ret = ff_get_encode_buffer(avctx, avpkt, output_size, 0)) < 0)
         return ret;
 
@@ -229,7 +229,8 @@ static int aptx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         aptx_encode_samples(s, samples, avpkt->data + pos);
     }
 
-    ff_af_queue_remove(&s->afq, frame->nb_samples, &avpkt->pts, &avpkt->duration);
+    ff_af_queue_remove(&s->afq, frame->nb_samples & ~3,
+                       &avpkt->pts, &avpkt->duration);
     *got_packet_ptr = 1;
     return 0;
 }
diff --git a/tests/ref/fate/aptx b/tests/ref/fate/aptx
index 35729b77c7..ccc3a49ac9 100644
--- a/tests/ref/fate/aptx
+++ b/tests/ref/fate/aptx
@@ -1,5 +1,5 @@
-b5d8a297c0e8d9854f19d9d3e8b82859 *tests/data/fate/aptx.aptx
-418950 tests/data/fate/aptx.aptx
+966f4391a8472208409a52603494846f *tests/data/fate/aptx.aptx
+418948 tests/data/fate/aptx.aptx
 #tb 0: 1/44100
 #media_type 0: audio
 #codec_id 0: pcm_s16le
diff --git a/tests/ref/fate/aptx-hd b/tests/ref/fate/aptx-hd
index fe611de03e..a3cb78daa5 100644
--- a/tests/ref/fate/aptx-hd
+++ b/tests/ref/fate/aptx-hd
@@ -1,5 +1,5 @@
-48ecaa81ee5adaaa62ed3ff6574b6666 *tests/data/fate/aptx-hd.aptx_hd
-628425 tests/data/fate/aptx-hd.aptx_hd
+0bb7bb4313bd33fe44e409c67d392fd0 *tests/data/fate/aptx-hd.aptx_hd
+628422 tests/data/fate/aptx-hd.aptx_hd
 #tb 0: 1/44100
 #media_type 0: audio
 #codec_id 0: pcm_s32le
-- 
2.30.2



More information about the ffmpeg-devel mailing list