]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix #851 : sudo zstd -t file.zst changes /dev/null permissions 852/head
authorYann Collet <cyan@fb.com>
Mon, 18 Sep 2017 20:41:54 +0000 (13:41 -0700)
committerYann Collet <cyan@fb.com>
Mon, 18 Sep 2017 20:41:54 +0000 (13:41 -0700)
reported by @mike155

NEWS
programs/fileio.c

diff --git a/NEWS b/NEWS
index 1300c80d4c27e3f7f6019539a0d702926accf01a..bb7eaaca850f5071ad9e69c10d25bfba36e3fcb1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,12 @@
 v1.3.2
+new : long range mode, using --long command, by Stella Lau (@stellamplau)
 license : changed /examples license to BSD + GPLv2
 license : fix a few header files to reflect new license (#825)
-fix : 32-bits build can now decode large offsets (levels 21+)
+fix : multi-threading compression works with custom allocators
 fix : a rare compression bug when compression generates very large distances (only possible at --ultra -22)
+fix : 32-bits build can now decode large offsets (levels 21+)
+cli : new : can split input file for dictionary training, using command -B#
+cli : fix : do not change /dev/null permissions when using command -t with root access, reported by @mike155 (#851)
 build: fix : no-multithread variant compiles without pool.c dependency, reported by Mitchell Blank Jr (@mitchblank) (#819)
 build: better compatibility with reproducible builds, by Bernhard M. Wiedemann (@bmwiedemann) (#818)
 
index cef3f2c9e3901221d58e840b61051989ad962041..623c4f4df9334fb782a064e61f971df5a839a83d 100644 (file)
@@ -105,9 +105,6 @@ static clock_t g_time = 0;
 #define MIN(a,b)    ((a) < (b) ? (a) : (b))
 
 
-/*-*************************************
-*  Errors
-***************************************/
 /*-*************************************
 *  Debug
 ***************************************/
@@ -1023,8 +1020,8 @@ int FIO_compressMultipleFilenames(const char** inFileNamesTable, unsigned nbFile
  ***************************************************************************/
 typedef struct {
     void*  srcBuffer;
-    size_t srcBufferLoaded;
     size_t srcBufferSize;
+    size_t srcBufferLoaded;
     void*  dstBuffer;
     size_t dstBufferSize;
     ZSTD_DStream* dctx;
@@ -1560,11 +1557,11 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* dstFileName, const ch
 
     /* Close file */
     if (fclose(srcFile)) {
-        DISPLAYLEVEL(1, "zstd: %s: %s \n", srcFileName, strerror(errno));  /* error should never happen */
+        DISPLAYLEVEL(1, "zstd: %s: %s \n", srcFileName, strerror(errno));  /* error should not happen */
         return 1;
     }
     if ( g_removeSrcFile /* --rm */
-      && (result==0)   /* decompression successful */
+      && (result==0)     /* decompression successful */
       && strcmp(srcFileName, stdinmark) ) /* not stdin */ {
         if (remove(srcFileName)) {
             /* failed to remove src file */
@@ -1590,7 +1587,8 @@ static int FIO_decompressDstFile(dRess_t ress,
     ress.dstFile = FIO_openDstFile(dstFileName);
     if (ress.dstFile==0) return 1;
 
-    if (strcmp (srcFileName, stdinmark) && UTIL_getFileStat(srcFileName, &statbuf))
+    if ( strcmp(srcFileName, stdinmark)
+      && UTIL_getFileStat(srcFileName, &statbuf) )
         stat_result = 1;
     result = FIO_decompressSrcFile(ress, dstFileName, srcFileName);
 
@@ -1600,11 +1598,15 @@ static int FIO_decompressDstFile(dRess_t ress,
     }
 
     if ( (result != 0)  /* operation failure */
-       && strcmp(dstFileName, nulmark)  /* special case : don't remove() /dev/null (#316) */
-       && remove(dstFileName) /* remove artefact */ )
-        result=1;   /* don't do anything special if remove() fails */
-    else if (strcmp (dstFileName, stdoutmark) && stat_result)
-        UTIL_setFileStat(dstFileName, &statbuf);
+      && strcmp(dstFileName, nulmark)      /* special case : don't remove() /dev/null (#316) */
+      && strcmp(dstFileName, stdoutmark) ) /* special case : don't remove() stdout */
+        remove(dstFileName);  /* remove decompression artefact; note don't do anything special if remove() fails */
+    else {  /* operation success */
+        if ( strcmp(dstFileName, stdoutmark) /* special case : don't chmod stdout */
+          && strcmp(dstFileName, nulmark)    /* special case : don't chmod /dev/null */
+          && stat_result )                   /* file permissions correctly extracted from src */
+            UTIL_setFileStat(dstFileName, &statbuf);  /* transfer file permissions from src into dst */
+    }
     return result;
 }