61bb31
--- ./libcdio-0.92/lib/iso9660/iso9660_fs.c	2018-06-06 11:52:23.464809984 +0200
61bb31
+++ ../libcdio-fedora/libcdio-0.94/lib/iso9660/iso9660_fs.c	2018-06-05 18:18:31.235215219 +0200
61bb31
@@ -714,6 +714,7 @@
61bb31
   iso711_t i_fname;
61bb31
   unsigned int stat_len;
61bb31
   iso9660_stat_t *p_stat;
61bb31
+  bool err;
61bb31
 
61bb31
   if (!dir_len) return NULL;
61bb31
 
61bb31
@@ -730,8 +731,16 @@
61bb31
     }
61bb31
   p_stat->type    = (p_iso9660_dir->file_flags & ISO_DIRECTORY)
61bb31
     ? _STAT_DIR : _STAT_FILE;
61bb31
-  p_stat->lsn     = from_733 (p_iso9660_dir->extent);
61bb31
-  p_stat->size    = from_733 (p_iso9660_dir->size);
61bb31
+  p_stat->lsn     = from_733_with_err (p_iso9660_dir->extent, &err;;
61bb31
+  if (err) {
61bb31
+    free(p_stat);
61bb31
+    return NULL;
61bb31
+  }
61bb31
+  p_stat->size    = from_733_with_err (p_iso9660_dir->size, &err;;
61bb31
+  if (err) {
61bb31
+    free(p_stat);
61bb31
+    return NULL;
61bb31
+  }
61bb31
   p_stat->secsize = _cdio_len2blocks (p_stat->size, ISO_BLOCKSIZE);
61bb31
   p_stat->rr.b3_rock = dunno; /*FIXME should do based on mask */
61bb31
   p_stat->b_xa    = false;
61bb31
@@ -754,6 +763,7 @@
61bb31
         if (!p_stat_new)
61bb31
           {
61bb31
           cdio_warn("Couldn't calloc(1, %d)", (int)(sizeof(iso9660_stat_t)+i_rr_fname+2));
61bb31
+	  free(p_stat);
61bb31
           return NULL;
61bb31
           }
61bb31
 	memcpy(p_stat_new, p_stat, stat_len);
61bb31
@@ -1098,6 +1108,12 @@
61bb31
       p_stat = _iso9660_dir_to_statbuf (p_iso9660_dir, p_iso->b_xa,
61bb31
 					p_iso->u_joliet_level);
61bb31
 
61bb31
+      if (!p_stat) {
61bb31
+	cdio_warn("Bad directory information for %s", splitpath[0]);
61bb31
+	free(_dirbuf);
61bb31
+	return NULL;
61bb31
+      }
61bb31
+
61bb31
       cmp = strcmp(splitpath[0], p_stat->filename);
61bb31
 
61bb31
       if ( 0 != cmp && 0 == p_iso->u_joliet_level
61bb31
@@ -1283,12 +1299,15 @@
61bb31
     if (!_dirbuf)
61bb31
       {
61bb31
       cdio_warn("Couldn't calloc(1, %d)", p_stat->secsize * ISO_BLOCKSIZE);
61bb31
+      _cdio_list_free (retval, true);
61bb31
       return NULL;
61bb31
       }
61bb31
 
61bb31
     if (cdio_read_data_sectors (p_cdio, _dirbuf, p_stat->lsn,
61bb31
-				ISO_BLOCKSIZE, p_stat->secsize))
61bb31
-	return NULL;
61bb31
+				ISO_BLOCKSIZE, p_stat->secsize)) {
61bb31
+      _cdio_list_free (retval, true);
61bb31
+      return NULL;
61bb31
+    }
61bb31
 
61bb31
     while (offset < (p_stat->secsize * ISO_BLOCKSIZE))
61bb31
       {
61bb31
@@ -1401,14 +1417,14 @@
61bb31
       }
61bb31
 
61bb31
     free (_dirbuf);
61bb31
+    free(p_stat->rr.psz_symlink);
61bb31
 
61bb31
-    if (offset != (p_stat->secsize * ISO_BLOCKSIZE)) {
61bb31
-      free (p_stat);
61bb31
+    if (offset != (p_stat->secsize * ISO_BLOCKSIZE)) {
61bb31
+      free (p_stat);
61bb31
       _cdio_list_free (retval, true);
61bb31
       return NULL;
61bb31
     }
61bb31
 
61bb31
-    free (p_stat->rr.psz_symlink);
61bb31
     free (p_stat);
61bb31
     return retval;
61bb31
   }
61bb31
@@ -1528,6 +1563,16 @@
61bb31
 }
61bb31
 
61bb31
 /*!
61bb31
+  Free the passed iso9660_stat_t structure.
61bb31
+ */
61bb31
+void
61bb31
+iso9660_stat_free(iso9660_stat_t *p_stat)
61bb31
+{
61bb31
+  if (p_stat != NULL)
61bb31
+    free(p_stat);
61bb31
+}
61bb31
+
61bb31
+/*!
61bb31
   Return true if ISO 9660 image has extended attrributes (XA).
61bb31
 */
61bb31
 bool
61bb31
@@ -1580,11 +1625,11 @@
61bb31
       if ( have_rr != yep) {
61bb31
 	have_rr = iso_have_rr_traverse (p_iso, p_stat, &splitpath[1], pu_file_limit);
61bb31
       }
61bb31
+      free(p_stat);
61bb31
       if (have_rr != nope) {
61bb31
 	free (_dirbuf);
61bb31
 	return have_rr;
61bb31
       }
61bb31
-      free(p_stat);
61bb31
 
61bb31
       offset += iso9660_get_dir_len(p_iso9660_dir);
61bb31
       *pu_file_limit = (*pu_file_limit)-1;