diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 09b6a2f17d6ee2b3d216e27f674dee5ec8a8d39f..e39338870f0ea99ab38a24b42fc0366fa39e2635 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);