diff --git a/libavcodec/g726.c b/libavcodec/g726.c
index 15c5fa66207a17de4e1585c174242e16769c937a..13dce4f590804faf3ad9214d04216cd801cacff7 100644
--- a/libavcodec/g726.c
+++ b/libavcodec/g726.c
@@ -334,6 +334,10 @@ static av_cold int g726_init(AVCodecContext * avctx)
         av_log(avctx, AV_LOG_ERROR, "G726: unsupported audio format\n");
         return -1;
     }
+    if(index>3){
+        av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2);
+        return -1;
+    }
     g726_reset(&c->c, index);
     c->code_size = c->c.tbls->bits;
     c->bit_buffer = 0;