--- wv-clean/sprm.c	2010-10-09 18:28:40.000000000 +0800
+++ wv-fix2/sprm.c	2026-11-05 15:47:30.856032431 +0800
@@ -1075,6 +1075,7 @@
     U16 istdFirst;
     U16 istdLast;
     U16 *rgistd;
+    U16 nistd = 0;
     U16 i;
 
     cch = dread_8ubit (NULL, &pointer);
@@ -1090,7 +1091,8 @@
 
     if ( cch > 6)
       {
-	  rgistd = (U16 *) wvMalloc (sizeof (U16) * ((cch - 6) / 2));
+	  nistd = (U16) ((cch - 6) / 2);
+	  rgistd = (U16 *) wvMalloc (sizeof (U16) * nistd);
 	  if (rgistd == NULL)
 	    {
 		wvError (
@@ -1098,7 +1100,7 @@
 			  sizeof (U16) * ((cch - 6) / 2)));
 		return;
 	    }
-	  for (i = 0; i < (cch - 6) / 2; i++)
+	  for (i = 0; i < nistd; i++)
 	    {
 		rgistd[i] = dread_16ubit (NULL, &pointer);
 		(*pos) += 2;
@@ -1113,7 +1115,8 @@
        has no effect. If it is, pap.istd is set to rgistd[pap.istd - istdFirst]
      */
 
-    if ((apap->istd > istdFirst) && (apap->istd <= istdLast))
+    if ((apap->istd > istdFirst) && (apap->istd <= istdLast)
+	&& ((U16) (apap->istd - istdFirst) < nistd))
       {
 	  wvTrace (("%d %d %d\n", apap->istd, istdFirst, istdLast));
 	  apap->istd = rgistd[apap->istd - istdFirst];
