]> wimlib.net Git - wimlib/blobdiff - src/extract.c
do_wimlib_extract_image(): Do not allow GLOB_PATHS
[wimlib] / src / extract.c
index 8e695f665e879c6a5adae98535abd82b0320fb0d..8bbf3e7d5807d89e63f009e01b910f3be72ca73e 100644 (file)
 #define WIMLIB_EXTRACT_FLAG_FROM_PIPE   0x40000000
 #define WIMLIB_EXTRACT_FLAG_FILEMODE    0x20000000
 #define WIMLIB_EXTRACT_FLAG_IMAGEMODE   0x10000000
-#define WIMLIB_EXTRACT_MASK_PUBLIC      0x0fffffff
+
+/* Keep in sync with wimlib.h  */
+#define WIMLIB_EXTRACT_MASK_PUBLIC                             \
+       (WIMLIB_EXTRACT_FLAG_NTFS                       |       \
+        WIMLIB_EXTRACT_FLAG_HARDLINK                   |       \
+        WIMLIB_EXTRACT_FLAG_SYMLINK                    |       \
+        WIMLIB_EXTRACT_FLAG_VERBOSE                    |       \
+        WIMLIB_EXTRACT_FLAG_SEQUENTIAL                 |       \
+        WIMLIB_EXTRACT_FLAG_UNIX_DATA                  |       \
+        WIMLIB_EXTRACT_FLAG_NO_ACLS                    |       \
+        WIMLIB_EXTRACT_FLAG_STRICT_ACLS                |       \
+        WIMLIB_EXTRACT_FLAG_RPFIX                      |       \
+        WIMLIB_EXTRACT_FLAG_NORPFIX                    |       \
+        WIMLIB_EXTRACT_FLAG_TO_STDOUT                  |       \
+        WIMLIB_EXTRACT_FLAG_REPLACE_INVALID_FILENAMES  |       \
+        WIMLIB_EXTRACT_FLAG_ALL_CASE_CONFLICTS         |       \
+        WIMLIB_EXTRACT_FLAG_STRICT_TIMESTAMPS          |       \
+        WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES         |       \
+        WIMLIB_EXTRACT_FLAG_STRICT_SYMLINKS            |       \
+        WIMLIB_EXTRACT_FLAG_RESUME                     |       \
+        WIMLIB_EXTRACT_FLAG_FILE_ORDER                 |       \
+        WIMLIB_EXTRACT_FLAG_GLOB_PATHS                 |       \
+        WIMLIB_EXTRACT_FLAG_STRICT_GLOB                |       \
+        WIMLIB_EXTRACT_FLAG_NO_ATTRIBUTES              |       \
+        WIMLIB_EXTRACT_FLAG_NO_PRESERVE_DIR_STRUCTURE)
 
 /* Given a WIM dentry in the tree to be extracted, resolve all streams in the
  * corresponding inode and set 'out_refcnt' in each to 0.  */
@@ -1383,32 +1407,17 @@ out_delete_tmpfile:
 static int
 extract_stream_list(struct apply_ctx *ctx)
 {
-       if (!(ctx->extract_flags & WIMLIB_EXTRACT_FLAG_FILE_ORDER)) {
-               /* Sequential extraction: read the streams in the order in which
-                * they appear in the WIM file.  */
-               struct read_stream_list_callbacks cbs = {
-                       .begin_stream           = begin_extract_stream_to_tmpfile,
-                       .begin_stream_ctx       = ctx,
-                       .consume_chunk          = extract_chunk_to_fd,
-                       .consume_chunk_ctx      = &ctx->tmpfile_fd,
-                       .end_stream             = end_extract_stream_to_tmpfile,
-                       .end_stream_ctx         = ctx,
-               };
-               return read_stream_list(&ctx->stream_list,
-                                       offsetof(struct wim_lookup_table_entry, extraction_list),
-                                       &cbs, VERIFY_STREAM_HASHES);
-       } else {
-               /* Extract the streams in unsorted order.  */
-               struct wim_lookup_table_entry *lte;
-               int ret;
-
-               list_for_each_entry(lte, &ctx->stream_list, extraction_list) {
-                       ret = extract_stream_instances(lte, lte, ctx);
-                       if (ret)
-                               return ret;
-               }
-               return 0;
-       }
+       struct read_stream_list_callbacks cbs = {
+               .begin_stream           = begin_extract_stream_to_tmpfile,
+               .begin_stream_ctx       = ctx,
+               .consume_chunk          = extract_chunk_to_fd,
+               .consume_chunk_ctx      = &ctx->tmpfile_fd,
+               .end_stream             = end_extract_stream_to_tmpfile,
+               .end_stream_ctx         = ctx,
+       };
+       return read_stream_list(&ctx->stream_list,
+                               offsetof(struct wim_lookup_table_entry, extraction_list),
+                               &cbs, VERIFY_STREAM_HASHES);
 }
 
 #define PWM_ALLOW_WIM_HDR 0x00001
@@ -2562,7 +2571,9 @@ check_extract_flags(const WIMStruct *wim, int *extract_flags_p)
 #endif
 
        if ((extract_flags & (WIMLIB_EXTRACT_FLAG_RPFIX |
-                             WIMLIB_EXTRACT_FLAG_NORPFIX)) == 0)
+                             WIMLIB_EXTRACT_FLAG_NORPFIX |
+                             WIMLIB_EXTRACT_FLAG_IMAGEMODE)) ==
+                                       WIMLIB_EXTRACT_FLAG_IMAGEMODE)
        {
                /* Do reparse point fixups by default if the WIM header says
                 * they are enabled.  */
@@ -2842,7 +2853,8 @@ do_wimlib_extract_image(WIMStruct *wim,
        int ret;
 
        if (extract_flags & (WIMLIB_EXTRACT_FLAG_NO_PRESERVE_DIR_STRUCTURE |
-                            WIMLIB_EXTRACT_FLAG_TO_STDOUT))
+                            WIMLIB_EXTRACT_FLAG_TO_STDOUT |
+                            WIMLIB_EXTRACT_FLAG_GLOB_PATHS))
                return WIMLIB_ERR_INVALID_PARAM;
 
        if (image == WIMLIB_ALL_IMAGES)
@@ -2881,9 +2893,12 @@ wimlib_extract_files(WIMStruct *wim,
        default_extract_flags |= WIMLIB_EXTRACT_FLAG_NO_PRESERVE_DIR_STRUCTURE;
 
        for (size_t i = 0; i < num_cmds; i++) {
-               int cmd_flags = ((cmds[i].extract_flags |
-                                 default_extract_flags) &
-                                       WIMLIB_EXTRACT_MASK_PUBLIC);
+               int cmd_flags = (cmds[i].extract_flags |
+                                default_extract_flags);
+
+               if (cmd_flags & ~WIMLIB_EXTRACT_MASK_PUBLIC)
+                       return WIMLIB_ERR_INVALID_PARAM;
+
                int cmd_link_flags = (cmd_flags & (WIMLIB_EXTRACT_FLAG_SYMLINK |
                                                   WIMLIB_EXTRACT_FLAG_HARDLINK));
                if (i == 0) {
@@ -2904,9 +2919,8 @@ wimlib_extract_files(WIMStruct *wim,
        }
 
        for (size_t i = 0; i < num_cmds; i++) {
-               int extract_flags = ((cmds[i].extract_flags |
-                                     default_extract_flags) &
-                                       WIMLIB_EXTRACT_MASK_PUBLIC);
+               int extract_flags = (cmds[i].extract_flags |
+                                    default_extract_flags);
                const tchar *target = cmds[i].fs_dest_path;
                const tchar *wim_source_path = cmds[i].wim_source_path;
 
@@ -2933,7 +2947,8 @@ wimlib_extract_paths(WIMStruct *wim,
 {
        int ret;
 
-       extract_flags &= WIMLIB_EXTRACT_MASK_PUBLIC;
+       if (extract_flags & ~WIMLIB_EXTRACT_MASK_PUBLIC)
+               return WIMLIB_ERR_INVALID_PARAM;
 
        ret = do_wimlib_extract_paths(wim, image, target, paths, num_paths,
                                      extract_flags, progress_func);
@@ -2979,7 +2994,8 @@ wimlib_extract_image_from_pipe(int pipe_fd, const tchar *image_num_or_name,
        int image;
        unsigned i;
 
-       extract_flags &= WIMLIB_EXTRACT_MASK_PUBLIC;
+       if (extract_flags & ~WIMLIB_EXTRACT_MASK_PUBLIC)
+               return WIMLIB_ERR_INVALID_PARAM;
 
        if (extract_flags & WIMLIB_EXTRACT_FLAG_FILE_ORDER)
                return WIMLIB_ERR_INVALID_PARAM;
@@ -3136,7 +3152,8 @@ wimlib_extract_image(WIMStruct *wim,
                     int extract_flags,
                     wimlib_progress_func_t progress_func)
 {
-       extract_flags &= WIMLIB_EXTRACT_MASK_PUBLIC;
+       if (extract_flags & ~WIMLIB_EXTRACT_MASK_PUBLIC)
+               return WIMLIB_ERR_INVALID_PARAM;
        return do_wimlib_extract_image(wim, image, target, extract_flags,
                                       progress_func);
 }