avcodec/cbs_av1: don't call cbs_av1_read_trailing_bits() when no bits remain in the OBU
authorJames Almer <jamrial@gmail.com>
Sun, 10 Feb 2019 20:41:38 +0000 (17:41 -0300)
committerJames Almer <jamrial@gmail.com>
Mon, 11 Feb 2019 00:02:06 +0000 (21:02 -0300)
Reviewed-by: jkqxz
Signed-off-by: James Almer <jamrial@gmail.com>
(cherry picked from commit 3e8b8b6b509c8c37defd3a8c32883fa54bc00de8)

libavcodec/cbs_av1.c

index 535139e..4513287 100644 (file)
@@ -1071,8 +1071,12 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
     if (obu->obu_size > 0 &&
         obu->header.obu_type != AV1_OBU_TILE_GROUP &&
         obu->header.obu_type != AV1_OBU_FRAME) {
-        err = cbs_av1_read_trailing_bits(ctx, &gbc,
-                                         obu->obu_size * 8 + start_pos - end_pos);
+        int nb_bits = obu->obu_size * 8 + start_pos - end_pos;
+
+        if (nb_bits <= 0)
+            return AVERROR_INVALIDDATA;
+
+        err = cbs_av1_read_trailing_bits(ctx, &gbc, nb_bits);
         if (err < 0)
             return err;
     }