diff -ru old/giflib-4.1.6/lib/dgif_lib.c giflib-4.1.6/lib/dgif_lib.c
--- old/giflib-4.1.6/lib/dgif_lib.c	2007-11-11 00:54:44.000000000 +0200
+++ giflib-4.1.6/lib/dgif_lib.c	2010-02-11 12:50:13.000000000 +0200
@@ -299,7 +299,10 @@
 
     if (READ(GifFile, &Buf, 1) != 1) {
         _GifError = D_GIF_ERR_READ_FAILED;
-        return GIF_ERROR;
+	fprintf(stderr, "Missing gif termination record.\n");
+        /* return GIF_ERROR; */
+	*Type = TERMINATE_RECORD_TYPE;
+	return GIF_OK;
     }
 
     switch (Buf) {
@@ -671,7 +674,12 @@
 
     if (READ(GifFile, &Buf, 1) != 1) {
         _GifError = D_GIF_ERR_READ_FAILED;
-        return GIF_ERROR;
+	fprintf(stderr, "Truncated gif file.\n");
+        /* return GIF_ERROR; */
+        *CodeBlock = NULL;
+        Private->Buf[0] = 0;    /* Make sure the buffer is empty! */
+        Private->PixelCount = 0;    /* And local info. indicate image read. */
+	return GIF_OK;
     }
 
     if (Buf > 0) {
@@ -759,8 +767,16 @@
     }
 
     while (i < LineLen) {    /* Decode LineLen items. */
-        if (DGifDecompressInput(GifFile, &CrntCode) == GIF_ERROR)
-            return GIF_ERROR;
+        if (DGifDecompressInput(GifFile, &CrntCode) == GIF_ERROR) {
+	    fprintf(stderr, "Invalid gif line, blanking %d of %d pixels.\n",
+		    LineLen-i, LineLen);
+            /* return GIF_ERROR; */
+	    for (; i < LineLen; ++i)
+		Line[i] = 0;
+	    Private->LastCode = LastCode;
+	    Private->StackPtr = StackPtr;
+	    return GIF_OK;
+	}
 
         if (CrntCode == EOFCode) {
             /* Note however that usually we will not be here as we will stop
@@ -981,9 +997,11 @@
                   GifByteType * NextByte) {
 
     if (Buf[0] == 0) {
+	int nread;
         /* Needs to read the next buffer - this one is empty: */
         if (READ(GifFile, Buf, 1) != 1) {
             _GifError = D_GIF_ERR_READ_FAILED;
+	    fprintf(stderr, "Truncated gif file, out of blocks to read.\n");
             return GIF_ERROR;
         }
         /* There shouldn't be any empty data blocks here as the LZW spec
@@ -994,9 +1012,15 @@
             _GifError = D_GIF_ERR_IMAGE_DEFECT;
             return GIF_ERROR;
         }
-        if (READ(GifFile, &Buf[1], Buf[0]) != Buf[0]) {
+	nread = READ(GifFile, &Buf[1], Buf[0]);
+        if (nread != Buf[0]) {
             _GifError = D_GIF_ERR_READ_FAILED;
-            return GIF_ERROR;
+	    fprintf(stderr, "Truncated data block: %d of %d bytes read.\n", nread, Buf[0]);
+	    if (nread < 0)
+		return GIF_ERROR;
+	    if (nread == 0)
+		return GIF_ERROR;
+	    Buf[0] = nread;
         }
         *NextByte = Buf[1];
         Buf[1] = 2;    /* We use now the second place as last char read! */
diff -ru old/giflib-4.1.6/lib/egif_lib.c giflib-4.1.6/lib/egif_lib.c
--- old/giflib-4.1.6/lib/egif_lib.c	2007-11-11 00:48:40.000000000 +0200
+++ giflib-4.1.6/lib/egif_lib.c	2010-02-11 12:51:25.000000000 +0200
@@ -101,13 +101,13 @@
 #if defined(__MSDOS__) || defined(WINDOWS32) || defined(_OPEN_BINARY)
                           | O_BINARY
 #endif /* __MSDOS__ */
-                          , S_IREAD | S_IWRITE);
+                          , S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
     else
         FileHandle = open(FileName, O_WRONLY | O_CREAT | O_TRUNC
 #if defined(__MSDOS__) || defined(WINDOWS32) || defined(_OPEN_BINARY)
                           | O_BINARY
 #endif /* __MSDOS__ */
-                          , S_IREAD | S_IWRITE);
+                          , S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
 
     if (FileHandle == -1) {
         _GifError = E_GIF_ERR_OPEN_FAILED;
diff -ru old/giflib-4.1.6/util/giftext.c giflib-4.1.6/util/giftext.c
--- old/giflib-4.1.6/util/giftext.c	2007-11-10 06:28:56.000000000 +0200
+++ giflib-4.1.6/util/giftext.c	2010-02-11 12:50:13.000000000 +0200
@@ -296,6 +296,7 @@
 			break;
 		    PrintExtBlock(Extension, FALSE);
 		}
+		PrintExtBlock(NULL, FALSE);
 		break;
 	    case TERMINATE_RECORD_TYPE:
 		break;
@@ -382,10 +383,10 @@
 		AsciiForm[CrntPlace] = 0;
 		if (Print) printf("\n%05lx: %-49s  %-17s\n",
 				ExtCount, HexForm, AsciiForm);
-		return;
 	    }
 	    else if (Print)
 		printf("\n");
+	    return;
 	}
 	CrntPlace = 0;
 	ExtCount = 0;
