--- bzip2-1.0.6/compress.c	2010-09-10 19:10:40.000000000 -0400
+++ compress.c	2014-07-18 13:23:43.081709887 -0400
@@ -28,6 +28,7 @@
 
 #include "bzlib_private.h"
 
+#include <assert.h>
 
 /*---------------------------------------------------*/
 /*--- Bit stream I/O                              ---*/
@@ -353,7 +354,8 @@
             Calculate the cost of this group as coded
             by each of the coding tables.
          --*/
-         for (t = 0; t < nGroups; t++) cost[t] = 0;
+         assert(nGroups <= BZ_N_GROUPS);
+         for (t = 0; t < BZ_N_GROUPS; t++) cost[t] = 0;
 
          if (nGroups == 6 && 50 == ge-gs+1) {
             /*--- fast track the common case ---*/
