Browse code

bb #4516 - fix for mszip compression in CAB files Thanks to Stefan Kuech

David Raynor authored on 2012/11/07 00:05:35
Showing 2 changed files
... ...
@@ -126,12 +126,22 @@ static const unsigned short mszip_bit_mask_tab[17] = {
126 126
 static int mszip_read_input(struct mszip_stream *zip) {
127 127
   int nread = zip->read_cb(zip->file, zip->inbuf, (int)zip->inbuf_size);
128 128
   if (nread < 0) {
129
-    if (zip->file->error == CL_BREAK)
130
-      return zip->error = CL_BREAK;
129
+    if (zip->file->error == CL_BREAK) {
130
+      if (nread == zip->last) {
131
+        cli_dbgmsg("mszip_read_input: Two consecutive CL_BREAKs reached.\n");
132
+        return CL_BREAK;
133
+      }
134
+      // Need short circuit to ensure scanning small files
135
+      cli_dbgmsg("mszip_read_input: First CL_BREAK reached.\n");
136
+      zip->i_ptr = zip->i_end;
137
+      zip->last = nread;
138
+      return CL_SUCCESS;
139
+    }
131 140
     else
132 141
       return zip->error = CL_EFORMAT;
133 142
   }
134 143
 
144
+  zip->last = nread;
135 145
   zip->i_ptr = &zip->inbuf[0];
136 146
   zip->i_end = &zip->inbuf[nread];
137 147
 
... ...
@@ -84,6 +84,7 @@ struct mszip_stream {
84 84
   int (*read_cb)(struct cab_file *, unsigned char *, int);
85 85
 
86 86
   unsigned char wflag;	    /* write flag */
87
+  unsigned int last;        /* prior end of content buffer */
87 88
 
88 89
 };
89 90