diff mbox series

[FFmpeg-devel,2/3] avcodec/siren: don't reduce getbitcontext size by checksum_bits at initialisation

Message ID 850ab9581cc2c568e34d013045b6db92a2c46fef.1631959242.git.pross@xvid.org
State Accepted
Commit e40593c0505a3ee143b8ac949af1bb70becafb21
Headers show
Series [FFmpeg-devel,1/3] avcodec/siren: prevent getbitcontext overread
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Peter Ross Sept. 18, 2021, 10:02 a.m. UTC
this allows the checksum calculation routine to also use getbitcontext
---
at the expense of having to offset get_bits_left(gb) everywhere

 libavcodec/siren.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/siren.c b/libavcodec/siren.c
index 3b0ad7b642..92fd3632f5 100644
--- a/libavcodec/siren.c
+++ b/libavcodec/siren.c
@@ -594,7 +594,7 @@  static int decode_vector(SirenContext *s, int number_of_regions,
             for (i = 0; i < number_of_vectors[category]; i++) {
                 index = 0;
                 do {
-                    if (get_bits_left(gb) <= 0) {
+                    if (get_bits_left(gb) - s->checksum_bits <= 0) {
                         error = 1;
                         break;
                     }
@@ -614,7 +614,7 @@  static int decode_vector(SirenContext *s, int number_of_regions,
                         index >>= index_table[category];
 
                         if (decoded_value) {
-                            if (get_bits_left(gb) <= 0) {
+                            if (get_bits_left(gb) - s->checksum_bits <= 0) {
                                 error = 1;
                                 break;
                             }
@@ -693,7 +693,7 @@  static int decode_vector(SirenContext *s, int number_of_regions,
         }
     }
 
-    return error == 1 ? AVERROR_INVALIDDATA : get_bits_left(gb);
+    return error == 1 ? AVERROR_INVALIDDATA : (get_bits_left(gb) - s->checksum_bits);
 }
 
 static int siren_decode(AVCodecContext *avctx, void *data,
@@ -712,7 +712,7 @@  static int siren_decode(AVCodecContext *avctx, void *data,
         if (avpkt->size < bits_per_frame / 8)
             return AVERROR_INVALIDDATA;
 
-        if ((ret = init_get_bits(gb, avpkt->data, bits_per_frame - s->checksum_bits)) < 0)
+        if ((ret = init_get_bits(gb, avpkt->data, bits_per_frame)) < 0)
             return ret;
     } else
     if ((ret = init_get_bits8(gb, avpkt->data, avpkt->size)) < 0)
@@ -726,7 +726,7 @@  static int siren_decode(AVCodecContext *avctx, void *data,
 
     rate_control = get_bits(gb, 4);
 
-    ret = categorize_regions(s->number_of_regions, get_bits_left(gb),
+    ret = categorize_regions(s->number_of_regions, get_bits_left(gb) - s->checksum_bits,
                              s->absolute_region_power_index, s->power_categories,
                              s->category_balance);
     if (ret < 0)
@@ -741,11 +741,11 @@  static int siren_decode(AVCodecContext *avctx, void *data,
     if (ret < 0 && !s->microsoft)
         return ret;
 
-    if (get_bits_left(gb) > 0) {
+    if (get_bits_left(gb) - s->checksum_bits > 0) {
         do {
             frame_error |= !get_bits1(gb);
-        } while (get_bits_left(gb) > 0);
-    } else if (get_bits_left(gb) < 0 &&
+        } while (get_bits_left(gb) - s->checksum_bits > 0);
+    } else if (get_bits_left(gb) - s->checksum_bits < 0 &&
                rate_control + 1 < s->rate_control_possibilities) {
         frame_error = 1;
     }