diff mbox series

[FFmpeg-devel] libavcodec/cbs_av1: Add size check before parse obu

Message ID 20220323072507.584505-1-wenbin.chen@intel.com
State New
Headers show
Series [FFmpeg-devel] libavcodec/cbs_av1: Add size check before parse obu | expand


Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Chen, Wenbin March 23, 2022, 7:25 a.m. UTC
cbs_av1_write_unit() check pbc size after parsing obu frame, and return
AVERROR(ENOSPC) if pbc is small. pbc will be reallocated and this obu
frame will be parsed again, but this may cause error because
CodedBitstreamAV1Context has already been updated, for example
ref_order_hint is updated and will not match the same obu frame. Now size
check is added before parsing obu frame to avoid this error.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
 libavcodec/cbs_av1.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series


diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 1229480567..571d3c15c3 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -1075,6 +1075,9 @@  static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
         put_bits32(pbc, 0);
+    if (8 * unit->data_size > put_bits_left(pbc))
+        return AVERROR(ENOSPC);
     td = NULL;
     start_pos = put_bits_count(pbc);
@@ -1196,9 +1199,6 @@  static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
     av_assert0(data_pos <= start_pos);
-    if (8 * obu->obu_size > put_bits_left(pbc))
-        return AVERROR(ENOSPC);
     if (obu->obu_size > 0) {
         memmove(pbc->buf + data_pos,
                 pbc->buf + start_pos, header_size);