increased the suffix/prefix size to 8192
authorClaus Gittinger <cg@exept.de>
Tue, 14 Feb 2017 15:55:58 +0100
changeset 7894 16136333fe33
parent 7893 3af8d2fd463b
child 7895 cd3eef1d2398
increased the suffix/prefix size to 8192 yes, there are gif images around which need that.
ImageReader.st
--- a/ImageReader.st	Mon Feb 13 20:50:16 2017 +0100
+++ b/ImageReader.st	Tue Feb 14 15:55:58 2017 +0100
@@ -710,6 +710,8 @@
 __decodeGIF__(unsigned char *from, unsigned char *to, int inCount, int initialCodeLen, int fromSize, int toSize)
 {
     register unsigned code;
+    // #define GIF_PREFIX_SUFFIX_SIZE 4096
+    #define GIF_PREFIX_SUFFIX_SIZE (4096*2)
     unsigned short *prefix;
     unsigned short *suffix;
     unsigned short *outCode;
@@ -735,14 +737,14 @@
 	}
 	return 0;
     }
-    prefix = (unsigned short *)malloc(sizeof(short) * 4096);
+    prefix = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE);
     if (! prefix) return 0;
-    suffix  = (unsigned short *)malloc(sizeof(short) * 4096);
+    suffix  = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE);
     if (! suffix) {
 	free(prefix);
 	return 0;
     }
-    outCode = (unsigned short *)malloc(sizeof(short) * 4096);
+    outCode = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE);
     if (! outCode) {
 	free(prefix);
 	free(suffix);
@@ -814,9 +816,9 @@
 		}
 
 		/* debugging and protecting myself from overwrites */
-		if (curCode >= 4096) {
+		if (curCode > (GIF_PREFIX_SUFFIX_SIZE-1)) {
 		    if (@global(InfoPrinting) == true) {
-			console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (code > 4095)\n");
+			console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (code > %d)\n", (GIF_PREFIX_SUFFIX_SIZE-1));
 		    }
 		    ret = 0;
 		    break;
@@ -850,9 +852,9 @@
 	    outCount = 0;
 
 	    /* debugging and protecting myself from overwrites */
-	    if (freeCode >= 4096) {
+	    if (freeCode > (GIF_PREFIX_SUFFIX_SIZE-1)) {
 		if (@global(InfoPrinting) == true) {
-		    console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (freeCode > 4095)\n");
+		    console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (freeCode > %d)\n", (GIF_PREFIX_SUFFIX_SIZE-1));
 		}
 		ret = 0;
 		break;
@@ -1675,7 +1677,7 @@
 save:anImage onFile:aFileName
     "save the image in my format on aFileName.
      Returns the imageReader instance (bad name; is a writer).
-     May raise Image cannotRepresentImageSignal, 
+     May raise Image cannotRepresentImageSignal,
      if the image cannot be represented in that format,
      or it is not support"
 
@@ -1690,7 +1692,7 @@
      The qualityPercent argument is ignored by all lossless formats.
      (however, JPG does care for it.)
      Returns the imageReader instance (bad name; is a writer).
-     May raise Image cannotRepresentImageSignal, 
+     May raise Image cannotRepresentImageSignal,
      if the image cannot be represented in that format,
      or it is not support"
 
@@ -1703,7 +1705,7 @@
 save:anImage onStream:aStream
     "save the image in my format on aStream.
      Returns the imageReader instance (bad name; is a writer).
-     May raise Image cannotRepresentImageSignal, 
+     May raise Image cannotRepresentImageSignal,
      if the image cannot be represented in that format,
      or it is not support"
 
@@ -1718,7 +1720,7 @@
      The qualityPercent argument is ignored by all lossless formats.
      (however, JPG does care for it.)
      Returns the imageReader instance (bad name; is a writer).
-     May raise Image cannotRepresentImageSignal, 
+     May raise Image cannotRepresentImageSignal,
      if the image cannot be represented in that format,
      or it is not support"
 
@@ -2162,23 +2164,23 @@
     |stream|
 
     [
-        stream := aFileName asFilename newReadWriteStream.
+	stream := aFileName asFilename newReadWriteStream.
     ] on:FileStream openErrorSignal do:[:ex|
-        ^ Image fileCreationErrorSignal
-            raiseWith:something
-            errorString:('file creation error: ' , aFileName asString).
+	^ Image fileCreationErrorSignal
+	    raiseWith:something
+	    errorString:('file creation error: ' , aFileName asString).
     ].
 
     [
-        [
-            aBlock value: stream
-        ] ensure:[
-            stream close.
-        ].
+	[
+	    aBlock value: stream
+	] ensure:[
+	    stream close.
+	].
     ] ifCurtailed:[
-        OsError catch:[
-            aFileName asFilename delete.
-        ]
+	OsError catch:[
+	    aFileName asFilename delete.
+	]
     ].
 ! !
 
@@ -2246,4 +2248,3 @@
 version_CVS
     ^ '$Header$'
 ! !
-