Blame SOURCES/lz4-1.7.5-dont-change-dev-null.patch

754a51
From a33bf89c62b1573a604144adaa797d94d97cb990 Mon Sep 17 00:00:00 2001
754a51
From: Yann Collet <cyan@fb.com>
754a51
Date: Wed, 15 Mar 2017 17:20:22 -0700
754a51
Subject: [PATCH] fix #332 : do not modify /dev/null permissions
754a51
754a51
---
754a51
 NEWS             |  4 +++
754a51
 programs/lz4io.c | 68 ++++++++++++++++++++++--------------------------
754a51
 programs/util.h  | 10 +++----
754a51
 3 files changed, 40 insertions(+), 42 deletions(-)
754a51
754a51
diff --git a/programs/lz4io.c b/programs/lz4io.c
754a51
index 5264b148..5bf54744 100644
754a51
--- a/programs/lz4io.c
754a51
+++ b/programs/lz4io.c
754a51
@@ -222,7 +222,7 @@ static int LZ4IO_isSkippableMagicNumber(unsigned int magic) { return (magic & LZ
754a51
 
754a51
 
754a51
 /** LZ4IO_openSrcFile() :
754a51
- * condition : `dstFileName` must be non-NULL.
754a51
+ * condition : `srcFileName` must be non-NULL.
754a51
  * @result : FILE* to `dstFileName`, or NULL if it fails */
754a51
 static FILE* LZ4IO_openSrcFile(const char* srcFileName)
754a51
 {
754a51
@@ -291,7 +291,7 @@ static FILE* LZ4IO_openDstFile(const char* dstFileName)
754a51
 /* unoptimized version; solves endianess & alignment issues */
754a51
 static void LZ4IO_writeLE32 (void* p, unsigned value32)
754a51
 {
754a51
-    unsigned char* dstPtr = (unsigned char*)p;
754a51
+    unsigned char* const dstPtr = (unsigned char*)p;
754a51
     dstPtr[0] = (unsigned char)value32;
754a51
     dstPtr[1] = (unsigned char)(value32 >> 8);
754a51
     dstPtr[2] = (unsigned char)(value32 >> 16);
754a51
@@ -317,10 +317,10 @@ int LZ4IO_compressFilename_Legacy(const char* input_filename, const char* output
754a51
     const int outBuffSize = LZ4_compressBound(LEGACY_BLOCKSIZE);
754a51
     FILE* finput;
754a51
     FILE* foutput;
754a51
-    clock_t end;
754a51
+    clock_t clockEnd;
754a51
 
754a51
     /* Init */
754a51
-    clock_t const start = clock();
754a51
+    clock_t const clockStart = clock();
754a51
     if (compressionlevel < 3) compressionFunction = LZ4IO_LZ4_compress; else compressionFunction = LZ4_compress_HC;
754a51
 
754a51
     finput = LZ4IO_openSrcFile(input_filename);
754a51
@@ -336,7 +336,7 @@ int LZ4IO_compressFilename_Legacy(const char* input_filename, const char* output
754a51
     /* Write Archive Header */
754a51
     LZ4IO_writeLE32(out_buff, LEGACY_MAGICNUMBER);
754a51
     { size_t const sizeCheck = fwrite(out_buff, 1, MAGICNUMBER_SIZE, foutput);
754a51
-      if (sizeCheck!=MAGICNUMBER_SIZE) EXM_THROW(22, "Write error : cannot write header"); }
754a51
+      if (sizeCheck != MAGICNUMBER_SIZE) EXM_THROW(22, "Write error : cannot write header"); }
754a51
 
754a51
     /* Main Loop */
754a51
     while (1) {
754a51
@@ -360,13 +360,13 @@ int LZ4IO_compressFilename_Legacy(const char* input_filename, const char* output
754a51
     if (ferror(finput)) EXM_THROW(25, "Error while reading %s ", input_filename);
754a51
 
754a51
     /* Status */
754a51
-    end = clock();
754a51
-    if (end==start) end+=1;  /* avoid division by zero (speed) */
754a51
+    clockEnd = clock();
754a51
+    if (clockEnd==clockStart) clockEnd+=1;  /* avoid division by zero (speed) */
754a51
     filesize += !filesize;   /* avoid division by zero (ratio) */
754a51
     DISPLAYLEVEL(2, "\r%79s\r", "");   /* blank line */
754a51
     DISPLAYLEVEL(2,"Compressed %llu bytes into %llu bytes ==> %.2f%%\n",
754a51
         filesize, compressedfilesize, (double)compressedfilesize / filesize * 100);
754a51
-    {   double const seconds = (double)(end - start) / CLOCKS_PER_SEC;
754a51
+    {   double const seconds = (double)(clockEnd - clockStart) / CLOCKS_PER_SEC;
754a51
         DISPLAYLEVEL(4,"Done in %.2f s ==> %.2f MB/s\n", seconds, (double)filesize / seconds / 1024 / 1024);
754a51
     }
754a51
 
754a51
@@ -603,11 +603,11 @@ static unsigned LZ4IO_readLE32 (const void* s)
754a51
     return value32;
754a51
 }
754a51
 
754a51
-#define sizeT sizeof(size_t)
754a51
-#define maskT (sizeT - 1)
754a51
 
754a51
 static unsigned LZ4IO_fwriteSparse(FILE* file, const void* buffer, size_t bufferSize, unsigned storedSkips)
754a51
 {
754a51
+    const size_t sizeT = sizeof(size_t);
754a51
+    const size_t maskT = sizeT -1 ;
754a51
     const size_t* const bufferT = (const size_t*)buffer;   /* Buffer is supposed malloc'ed, hence aligned on size_t */
754a51
     const size_t* ptrT = bufferT;
754a51
     size_t bufferSizeT = bufferSize / sizeT;
754a51
@@ -682,22 +682,19 @@ static void LZ4IO_fwriteSparseEnd(FILE* file, unsigned storedSkips)
754a51
 }
754a51
 
754a51
 
754a51
-static unsigned g_magicRead = 0;
754a51
+static unsigned g_magicRead = 0;   /* out-parameter of LZ4IO_decodeLegacyStream() */
754a51
 static unsigned long long LZ4IO_decodeLegacyStream(FILE* finput, FILE* foutput)
754a51
 {
754a51
-    unsigned long long filesize = 0;
754a51
-    char* in_buff;
754a51
-    char* out_buff;
754a51
+    unsigned long long streamSize = 0;
754a51
     unsigned storedSkips = 0;
754a51
 
754a51
     /* Allocate Memory */
754a51
-    in_buff = (char*)malloc(LZ4_compressBound(LEGACY_BLOCKSIZE));
754a51
-    out_buff = (char*)malloc(LEGACY_BLOCKSIZE);
754a51
+    char* const in_buff  = (char*)malloc(LZ4_compressBound(LEGACY_BLOCKSIZE));
754a51
+    char* const out_buff = (char*)malloc(LEGACY_BLOCKSIZE);
754a51
     if (!in_buff || !out_buff) EXM_THROW(51, "Allocation error : not enough memory");
754a51
 
754a51
     /* Main Loop */
754a51
     while (1) {
754a51
-        int decodeSize;
754a51
         unsigned int blockSize;
754a51
 
754a51
         /* Block Size */
754a51
@@ -716,13 +713,12 @@ static unsigned long long LZ4IO_decodeLegacyStream(FILE* finput, FILE* foutput)
754a51
           if (sizeCheck!=blockSize) EXM_THROW(52, "Read error : cannot access compressed block !"); }
754a51
 
754a51
         /* Decode Block */
754a51
-        decodeSize = LZ4_decompress_safe(in_buff, out_buff, blockSize, LEGACY_BLOCKSIZE);
754a51
-        if (decodeSize < 0) EXM_THROW(53, "Decoding Failed ! Corrupted input detected !");
754a51
-        filesize += decodeSize;
754a51
-
754a51
-        /* Write Block */
754a51
-        storedSkips = LZ4IO_fwriteSparse(foutput, out_buff, decodeSize, storedSkips);
754a51
-    }
754a51
+        {   int const decodeSize = LZ4_decompress_safe(in_buff, out_buff, blockSize, LEGACY_BLOCKSIZE);
754a51
+            if (decodeSize < 0) EXM_THROW(53, "Decoding Failed ! Corrupted input detected !");
754a51
+            streamSize += decodeSize;
754a51
+            /* Write Block */
754a51
+            storedSkips = LZ4IO_fwriteSparse(foutput, out_buff, decodeSize, storedSkips); /* success or die */
754a51
+    }   }
754a51
     if (ferror(finput)) EXM_THROW(54, "Read error : ferror");
754a51
 
754a51
     LZ4IO_fwriteSparseEnd(foutput, storedSkips);
754a51
@@ -731,7 +727,7 @@ static unsigned long long LZ4IO_decodeLegacyStream(FILE* finput, FILE* foutput)
754a51
     free(in_buff);
754a51
     free(out_buff);
754a51
 
754a51
-    return filesize;
754a51
+    return streamSize;
754a51
 }
754a51
 
754a51
 
754a51
@@ -925,10 +921,9 @@ static int LZ4IO_decompressSrcFile(dRess_t ress, const char* input_filename, con
754a51
 {
754a51
     FILE* const foutput = ress.dstFile;
754a51
     unsigned long long filesize = 0, decodedSize=0;
754a51
-    FILE* finput;
754a51
 
754a51
     /* Init */
754a51
-    finput = LZ4IO_openSrcFile(input_filename);
754a51
+    FILE* const finput = LZ4IO_openSrcFile(input_filename);
754a51
     if (finput==NULL) return 1;
754a51
 
754a51
     /* Loop over multiple streams */
754a51
@@ -954,10 +949,7 @@ static int LZ4IO_decompressSrcFile(dRess_t ress, const char* input_filename, con
754a51
 
754a51
 static int LZ4IO_decompressDstFile(dRess_t ress, const char* input_filename, const char* output_filename)
754a51
 {
754a51
-    FILE* foutput;
754a51
-
754a51
-    /* Init */
754a51
-    foutput = LZ4IO_openDstFile(output_filename);
754a51
+    FILE* const foutput = LZ4IO_openDstFile(output_filename);   /* success or die */
754a51
     if (foutput==NULL) return 1;   /* failure */
754a51
 
754a51
     ress.dstFile = foutput;
754a51
@@ -967,8 +959,11 @@ static int LZ4IO_decompressDstFile(dRess_t ress, const char* input_filename, con
754a51
 
754a51
     /* Copy owner, file permissions and modification time */
754a51
     {   stat_t statbuf;
754a51
-        if (strcmp (input_filename, stdinmark) && strcmp (output_filename, stdoutmark) && UTIL_getFileStat(input_filename, &statbuf))
754a51
-            UTIL_setFileStat(output_filename, &statbuf);
754a51
+        if (strcmp (input_filename, stdinmark)
754a51
+            && strcmp (output_filename, stdoutmark)
754a51
+            && strcmp (output_filename, nulmark)
754a51
+            && UTIL_getFileStat(input_filename, &statbuf))
754a51
+            UTIL_setFileStat(output_filename, &statbuf);  /* should return value be read ? or is silent fail good enough ? */
754a51
     }
754a51
 
754a51
     return 0;
754a51
@@ -982,10 +977,9 @@ int LZ4IO_decompressFilename(const char* input_filename, const char* output_file
754a51
 
754a51
     int const missingFiles = LZ4IO_decompressDstFile(ress, input_filename, output_filename);
754a51
 
754a51
-    {   clock_t const end = clock();
754a51
-        double const seconds = (double)(end - start) / CLOCKS_PER_SEC;
754a51
-        DISPLAYLEVEL(4, "Done in %.2f sec  \n", seconds);
754a51
-    }
754a51
+    clock_t const end = clock();
754a51
+    double const seconds = (double)(end - start) / CLOCKS_PER_SEC;
754a51
+    DISPLAYLEVEL(4, "Done in %.2f sec  \n", seconds);
754a51
 
754a51
     LZ4IO_freeDResources(ress);
754a51
     return missingFiles;
754a51
diff --git a/programs/util.h b/programs/util.h
754a51
index 044085f3..5a69c55c 100644
754a51
--- a/programs/util.h
754a51
+++ b/programs/util.h
754a51
@@ -199,9 +199,9 @@ UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf)
754a51
     int res = 0;
754a51
     struct utimbuf timebuf;
754a51
 
754a51
-	timebuf.actime = time(NULL);
754a51
-	timebuf.modtime = statbuf->st_mtime;
754a51
-	res += utime(filename, &timebuf);  /* set access and modification times */
754a51
+    timebuf.actime = time(NULL);
754a51
+    timebuf.modtime = statbuf->st_mtime;
754a51
+    res += utime(filename, &timebuf);  /* set access and modification times */
754a51
 
754a51
 #if !defined(_WIN32)
754a51
     res += chown(filename, statbuf->st_uid, statbuf->st_gid);  /* Copy ownership */