diff mbox

[FFmpeg-devel,3/3] avcodec/golomb: Speed up long ur_golomb codes

Message ID 20181109220725.8649-3-michael@niedermayer.cc
State Accepted
Commit 6b4c9854daba2eac01716c3445eb68e6ab8758ba
Headers show

Commit Message

Michael Niedermayer Nov. 9, 2018, 10:07 p.m. UTC
Fixes: Timeout
Fixes: 10972/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FLAC_fuzzer-5707569640243200

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/golomb.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Michael Niedermayer Nov. 13, 2018, 9:27 p.m. UTC | #1
On Fri, Nov 09, 2018 at 11:07:25PM +0100, Michael Niedermayer wrote:
> Fixes: Timeout
> Fixes: 10972/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FLAC_fuzzer-5707569640243200
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/golomb.h | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)

will apply

[...]
diff mbox

Patch

diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 5c25883626..fcc78f44c1 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -476,15 +476,19 @@  static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit,
         return buf;
     } else {
         int i;
-        for (i = 0; i < limit && SHOW_UBITS(re, gb, 1) == 0; i++) {
+        for (i = 0; i + MIN_CACHE_BITS <= limit && SHOW_UBITS(re, gb, MIN_CACHE_BITS) == 0; i += MIN_CACHE_BITS) {
             if (gb->size_in_bits <= re_index) {
                 CLOSE_READER(re, gb);
                 return -1;
             }
-            LAST_SKIP_BITS(re, gb, 1);
+            LAST_SKIP_BITS(re, gb, MIN_CACHE_BITS);
             UPDATE_CACHE(re, gb);
         }
-        SKIP_BITS(re, gb, 1);
+        for (; i < limit && SHOW_UBITS(re, gb, 1) == 0; i++) {
+            SKIP_BITS(re, gb, 1);
+        }
+        LAST_SKIP_BITS(re, gb, 1);
+        UPDATE_CACHE(re, gb);
 
         if (i < limit - 1) {
             if (k) {