From 0716bcce5bdc6299da2966f34cb62eba3f709be8 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michael@niedermayer.cc>
Date: Sat, 25 Feb 2017 21:07:23 +0100
Subject: [PATCH] avcodec/ituh263dec: Check for the bitstream end in
 ff_h263_decode_mb()

Fixes invalid shift

Fixes: 670/clusterfuzz-testcase-4852021066727424

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/ituh263dec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 09b6a2f17d6..e39338870f0 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -962,6 +962,9 @@ intra:
     }
 end:
 
+    if (get_bits_left(&s->gb) < 0)
+        return AVERROR_INVALIDDATA;
+
         /* per-MB end of slice check */
     {
         int v= show_bits(&s->gb, 16);
-- 
GitLab