]> wimlib.net Git - wimlib/blobdiff - src/extract.c
extract.c: Fix dereference of NULL in memory exhausted path
[wimlib] / src / extract.c
index 0663edd75ba92d4f736b8249d572b292e0adc04b..fb96f13f8723bf26d0e24f9acfd4e9d051bb22c6 100644 (file)
         WIMLIB_EXTRACT_FLAG_NO_PRESERVE_DIR_STRUCTURE  |       \
         WIMLIB_EXTRACT_FLAG_WIMBOOT)
 
+/* Send WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE or
+ * WIMLIB_PROGRESS_MSG_EXTRACT_METADATA.  */
+int
+do_file_extract_progress(struct apply_ctx *ctx, enum wimlib_progress_msg msg)
+{
+       ctx->count_until_file_progress = 512;  /* Arbitrary value to limit calls  */
+       return extract_progress(ctx, msg);
+}
+
 /* Check whether the extraction of a dentry should be skipped completely.  */
 static bool
 dentry_is_supported(struct wim_dentry *dentry,
@@ -260,7 +269,7 @@ load_streams_from_pipe(struct apply_ctx *ctx,
        }
        ret = 0;
 out:
-       if (found_lte->resource_location != RESOURCE_IN_WIM)
+       if (found_lte && found_lte->resource_location != RESOURCE_IN_WIM)
                FREE(rspec);
        free_lookup_table_entry(found_lte);
        return ret;
@@ -401,9 +410,13 @@ extract_from_tmpfile(const tchar *tmpfile_name, struct apply_ctx *ctx)
 {
        struct wim_lookup_table_entry tmpfile_lte;
        struct wim_lookup_table_entry *orig_lte = ctx->cur_stream;
-       const struct stream_owner *owners = stream_owners(orig_lte);
        const struct read_stream_list_callbacks *cbs = ctx->saved_cbs;
        int ret;
+       const u32 orig_refcnt = orig_lte->out_refcnt;
+
+       BUILD_BUG_ON(MAX_OPEN_STREAMS < ARRAY_LEN(orig_lte->inline_stream_owners));
+
+       struct stream_owner *owners = orig_lte->stream_owners;
 
        /* Copy the stream's data from the temporary file to each of its
         * destinations.
@@ -415,10 +428,8 @@ extract_from_tmpfile(const tchar *tmpfile_name, struct apply_ctx *ctx)
        memcpy(&tmpfile_lte, orig_lte, sizeof(struct wim_lookup_table_entry));
        tmpfile_lte.resource_location = RESOURCE_IN_FILE_ON_DISK;
        tmpfile_lte.file_on_disk = ctx->tmpfile_name;
-       tmpfile_lte.out_refcnt = 1;
-
-       for (u32 i = 0; i < orig_lte->out_refcnt; i++) {
-               tmpfile_lte.inline_stream_owners[0] = owners[i];
+       ret = 0;
+       for (u32 i = 0; i < orig_refcnt; i++) {
 
                /* Note: it usually doesn't matter whether we pass the original
                 * stream entry to callbacks provided by the extraction backend
@@ -429,9 +440,12 @@ extract_from_tmpfile(const tchar *tmpfile_name, struct apply_ctx *ctx)
                 * because it needs the original stream location in order to
                 * create the external backing reference.  */
 
+               orig_lte->out_refcnt = 1;
+               orig_lte->inline_stream_owners[0] = owners[i];
+
                ret = (*cbs->begin_stream)(orig_lte, cbs->begin_stream_ctx);
                if (ret)
-                       return ret;
+                       break;
 
                /* Extra SHA-1 isn't necessary here, but it shouldn't hurt as
                 * this case is very rare anyway.  */
@@ -439,10 +453,13 @@ extract_from_tmpfile(const tchar *tmpfile_name, struct apply_ctx *ctx)
                                     cbs->consume_chunk,
                                     cbs->consume_chunk_ctx);
 
-               return (*cbs->end_stream)(orig_lte, ret,
-                                         cbs->end_stream_ctx);
+               ret = (*cbs->end_stream)(orig_lte, ret, cbs->end_stream_ctx);
+               if (ret)
+                       break;
        }
-       return 0;
+       FREE(owners);
+       orig_lte->out_refcnt = 0;
+       return ret;
 }
 
 static int
@@ -1511,12 +1528,16 @@ check_extract_flags(const WIMStruct *wim, int *extract_flags_p)
        }
 #endif
 
-#ifndef __WIN32__
        if (extract_flags & WIMLIB_EXTRACT_FLAG_WIMBOOT) {
+#ifdef __WIN32__
+               if (!wim->filename)
+                       return WIMLIB_ERR_NO_FILENAME;
+#else
                ERROR("WIMBoot extraction is only supported on Windows!");
                return WIMLIB_ERR_UNSUPPORTED;
-       }
 #endif
+       }
+
 
        if ((extract_flags & (WIMLIB_EXTRACT_FLAG_RPFIX |
                              WIMLIB_EXTRACT_FLAG_NORPFIX |