091b7b5
Index: libarchive-2.8.4/libarchive/archive_read_support_format_iso9660.c
091b7b5
===================================================================
091b7b5
--- libarchive-2.8.4/libarchive/archive_read_support_format_iso9660.c
091b7b5
+++ libarchive-2.8.4/libarchive/archive_read_support_format_iso9660.c	2012-01-01 03:11:38.424123879 +0200
133909d
@@ -405,12 +405,12 @@
133909d
 static inline void cache_add_to_next_of_parent(struct iso9660 *iso9660,
133909d
 		    struct file_info *file);
133909d
 static inline struct file_info *cache_get_entry(struct iso9660 *iso9660);
133909d
-static void	heap_add_entry(struct heap_queue *heap,
133909d
+static int	heap_add_entry(struct archive_read *a, struct heap_queue *heap,
133909d
 		    struct file_info *file, uint64_t key);
133909d
 static struct file_info *heap_get_entry(struct heap_queue *heap);
133909d
 
133909d
-#define add_entry(iso9660, file)	\
133909d
-	heap_add_entry(&((iso9660)->pending_files), file, file->offset)
133909d
+#define add_entry(arch, iso9660, file)	\
133909d
+	heap_add_entry(arch, &((iso9660)->pending_files), file, file->offset)
133909d
 #define next_entry(iso9660)		\
133909d
 	heap_get_entry(&((iso9660)->pending_files))
133909d
 
091b7b5
@@ -967,10 +967,11 @@
091b7b5
 			child = parse_file_info(a, parent, p);
133909d
 			if (child == NULL)
133909d
 				return (ARCHIVE_FATAL);
091b7b5
-			if (child->cl_offset)
133909d
-				heap_add_entry(&(iso9660->cl_files),
133909d
-				    child, child->cl_offset);
091b7b5
-			else {
091b7b5
+			if (child->cl_offset) {
133909d
+				if (heap_add_entry(a, &(iso9660->cl_files),
133909d
+				    child, child->cl_offset) != ARCHIVE_OK)
133909d
+					return (ARCHIVE_FATAL);
091b7b5
+			} else {
133909d
 				if (child->multi_extent || multi != NULL) {
133909d
 					struct content *con;
091b7b5
 
133909d
@@ -993,15 +994,19 @@
133909d
 					con->next = NULL;
133909d
 					*multi->contents.last = con;
133909d
 					multi->contents.last = &(con->next);
133909d
-					if (multi == child)
133909d
-						add_entry(iso9660, child);
133909d
-					else {
133909d
+					if (multi == child) {
133909d
+						if (add_entry(a, iso9660, child)
133909d
+						    != ARCHIVE_OK)
133909d
+							return (ARCHIVE_FATAL);
133909d
+					} else {
133909d
 						multi->size += child->size;
133909d
 						if (!child->multi_extent)
133909d
 							multi = NULL;
133909d
 					}
133909d
 				} else
133909d
-					add_entry(iso9660, child);
133909d
+					if (add_entry(a, iso9660, child)
133909d
+					    != ARCHIVE_OK)
133909d
+						return (ARCHIVE_FATAL);
133909d
 			}
133909d
 		}
133909d
 	}
133909d
@@ -1014,7 +1019,8 @@
133909d
 }
133909d
 
133909d
 static int
133909d
-relocate_dir(struct iso9660 *iso9660, struct file_info *file)
133909d
+relocate_dir(struct archive_read *a, struct iso9660 *iso9660,
133909d
+	struct file_info *file)
133909d
 {
133909d
 	struct file_info *re;
133909d
 
133909d
@@ -1036,7 +1042,9 @@
133909d
 		return (1);
133909d
 	} else
133909d
 		/* This case is wrong pattern. */
133909d
-		heap_add_entry(&(iso9660->re_dirs), re, re->offset);
133909d
+		if (heap_add_entry(a, &(iso9660->re_dirs), re, re->offset)
133909d
+		    != ARCHIVE_OK)
133909d
+			return (ARCHIVE_FATAL);
133909d
 	return (0);
133909d
 }
133909d
 
091b7b5
@@ -1062,21 +1070,24 @@
091b7b5
 		    (strcmp(file->name.s, "rr_moved") == 0 ||
133909d
 		     strcmp(file->name.s, ".rr_moved") == 0)) {
133909d
 			iso9660->rr_moved = file;
091b7b5
-		} else if (file->re)
133909d
-			heap_add_entry(&(iso9660->re_dirs), file,
133909d
-			    file->offset);
091b7b5
-		else
091b7b5
+		} else if (file->re) {
133909d
+			if (heap_add_entry(a, &(iso9660->re_dirs), file,
133909d
+			    file->offset) != ARCHIVE_OK)
133909d
+				return (ARCHIVE_FATAL);
091b7b5
+		} else
133909d
 			cache_add_entry(iso9660, file);
133909d
 	}
133909d
 	if (file != NULL)
133909d
-		add_entry(iso9660, file);
133909d
+		if (add_entry(a, iso9660, file) != ARCHIVE_OK)
133909d
+			return (ARCHIVE_FATAL);
133909d
 
133909d
 	if (iso9660->rr_moved != NULL) {
133909d
 		/*
133909d
 		 * Relocate directory which rr_moved has.
133909d
 		 */
133909d
 		while ((file = heap_get_entry(&(iso9660->cl_files))) != NULL)
133909d
-			relocate_dir(iso9660, file);
133909d
+			if (relocate_dir(a, iso9660, file) != ARCHIVE_OK)
133909d
+				return ARCHIVE_FATAL;
133909d
 
133909d
 		/* If rr_moved directory still has children,
133909d
 		 * Add rr_moved into pending_files to show
133909d
@@ -1192,7 +1203,8 @@
133909d
 			iso9660->seenJoliet = seenJoliet;
133909d
 		}
133909d
 		/* Store the root directory in the pending list. */
133909d
-		add_entry(iso9660, file);
133909d
+		if (add_entry(a, iso9660, file) != ARCHIVE_OK)
133909d
+			return (ARCHIVE_FATAL);
133909d
 		if (iso9660->seenRockridge) {
133909d
 			a->archive.archive_format =
133909d
 			    ARCHIVE_FORMAT_ISO9660_ROCKRIDGE;
133909d
@@ -2619,8 +2631,8 @@
133909d
 	return (file);
133909d
 }
133909d
 
133909d
-static void
133909d
-heap_add_entry(struct heap_queue *heap, struct file_info *file, uint64_t key)
133909d
+static int
133909d
+heap_add_entry(struct archive_read *a, struct heap_queue *heap, struct file_info *file, uint64_t key)
133909d
 {
133909d
 	uint64_t file_key, parent_key;
133909d
 	int hole, parent;
133909d
@@ -2633,12 +2645,18 @@
133909d
 		if (heap->allocated < 1024)
133909d
 			new_size = 1024;
133909d
 		/* Overflow might keep us from growing the list. */
133909d
-		if (new_size <= heap->allocated)
133909d
-			__archive_errx(1, "Out of memory");
133909d
+		if (new_size <= heap->allocated) {
133909d
+			archive_set_error(&a->archive,
133909d
+			    ENOMEM, "Out of memory");
133909d
+			return (ARCHIVE_FATAL);
133909d
+		}
133909d
 		new_pending_files = (struct file_info **)
133909d
 		    malloc(new_size * sizeof(new_pending_files[0]));
133909d
-		if (new_pending_files == NULL)
133909d
-			__archive_errx(1, "Out of memory");
133909d
+		if (new_pending_files == NULL) {
133909d
+			archive_set_error(&a->archive,
133909d
+			    ENOMEM, "Out of memory");
133909d
+			return (ARCHIVE_FATAL);
133909d
+		}
133909d
 		memcpy(new_pending_files, heap->files,
133909d
 		    heap->allocated * sizeof(new_pending_files[0]));
133909d
 		if (heap->files != NULL)
091b7b5
@@ -2658,13 +2676,15 @@
091b7b5
 		parent_key = heap->files[parent]->key;
091b7b5
 		if (file_key >= parent_key) {
091b7b5
 			heap->files[hole] = file;
091b7b5
-			return;
091b7b5
+			return (ARCHIVE_OK);
091b7b5
 		}
091b7b5
 		// Move parent into hole <==> move hole up tree.
091b7b5
 		heap->files[hole] = heap->files[parent];
133909d
 		hole = parent;
133909d
 	}
133909d
 	heap->files[0] = file;
133909d
+
133909d
+	return (ARCHIVE_OK);
133909d
 }
133909d
 
133909d
 static struct file_info *