Zip Reader: initialise error string earlier.
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 13 May 2017 09:19:58 +0000 (11:19 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 13 May 2017 09:19:58 +0000 (11:19 +0200)
Fixed a bug which could have caused a crash if pspp were presented
with a corrupt zip file.

src/libpspp/inflate.c
src/libpspp/zip-reader.c
src/libpspp/zip-reader.h

index 9cdc11e6b21f48c982426e888871094d104ca750..0396674b1a8b12ecccd5c2d4c088efaaa7af69d2 100644 (file)
@@ -84,7 +84,7 @@ inflate_init (struct zip_member *zm)
 
   if ( Z_OK != r)
     {
-      ds_put_format (zm->errs, _("Cannot initialize inflator: %s"), zError (r));
+      ds_put_format (zm->errmsgs, _("Cannot initialize inflator: %s"), zError (r));
       return false;
     }
 
@@ -139,7 +139,7 @@ inflate_read (struct zip_member *zm, void *buf, size_t n)
       return n - inf->zss.avail_out;
     }
 
-  ds_put_format (zm->errs, _("Error inflating: %s"), zError (r));
+  ds_put_format (zm->errmsgs, _("Error inflating: %s"), zError (r));
 
   return -1;
 }
index 69ef4fb9187c3982ca33888f0915df532e0f77fc..13986cbeca21ac51ce6ef856cb37c1f70d6ff1e2 100644 (file)
@@ -73,6 +73,7 @@ static enum compression
 comp_code (struct zip_member *zm, uint16_t c)
 {
   enum compression which;
+  assert (zm->errmsgs);
   switch (c)
     {
     case 0:
@@ -82,7 +83,7 @@ comp_code (struct zip_member *zm, uint16_t c)
       which = COMPRESSION_INFLATE;
       break;
     default:
-      ds_put_format (zm->errs, _("Unsupported compression type (%d)"), c);
+      ds_put_format (zm->errmsgs, _("Unsupported compression type (%d)"), c);
       which = n_COMPRESSION;
       break;
     }
@@ -103,7 +104,7 @@ struct zip_reader
 void
 zip_member_finish (struct zip_member *zm)
 {
-  ds_clear (zm->errs);
+  ds_clear (zm->errmsgs);
   /*  Probably not useful, because we would have to read right to the end of the member
   if (zm->expected_crc != zm->crc)
     {
@@ -224,7 +225,7 @@ zip_member_read (struct zip_member *zm, void *buf, size_t bytes)
 {
   int bytes_read = 0;
 
-  ds_clear (zm->errs);
+  ds_clear (zm->errmsgs);
 
   if ( bytes > zm->bytes_unread)
     bytes = zm->bytes_unread;
@@ -260,6 +261,7 @@ zip_header_read_next (struct zip_reader *zr)
   uint16_t comp_type;
 
   ds_clear (zr->errs);
+  zm->errmsgs = zr->errs;
 
   if ( ! check_magic (zr->fr, MAGIC_SOCD, zr->errs))
     return NULL;
@@ -294,7 +296,7 @@ zip_header_read_next (struct zip_reader *zr)
 
   zm->fp = fopen (zr->filename, "rb");
   zm->ref_cnt = 1;
-  zm->errs = zr->errs;
+
 
   return zm;
 }
@@ -422,7 +424,7 @@ zip_member_open (struct zip_reader *zr, const char *member)
   if ( 0 != fseeko (zm->fp, zm->offset, SEEK_SET))
     {
       const char *mm = strerror (errno);
-      ds_put_format (zm->errs, _("Failed to seek to start of member `%s': %s"), zm->name, mm);
+      ds_put_format (zm->errmsgs, _("Failed to seek to start of member `%s': %s"), zm->name, mm);
       return NULL;
     }
 
@@ -452,7 +454,7 @@ zip_member_open (struct zip_reader *zr, const char *member)
 
   if (strcmp (name, zm->name) != 0)
     {
-      ds_put_format (zm->errs,
+      ds_put_format (zm->errmsgs,
                     _("Name mismatch in zip archive. Central directory says `%s'; local file header says `%s'"),
                     zm->name, name);
       free (name);
index ccb1ef39f1bd25d3e5cf9b34f2135e9675d20387..81c1a766dd60ed8ecca85f5375bf305e5e18f1f7 100644 (file)
@@ -43,7 +43,8 @@ struct zip_member
 
   size_t bytes_unread;       /* Number of bytes left in the member available for reading */
   int ref_cnt;
-  struct string *errs;
+  struct string *errmsgs;    /* A string to hold error messages.
+                               This string is NOT owned by this object. */
   void *aux;
 };