]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Merge branch 'dev' into scanbuild
authorYann Collet <cyan@fb.com>
Tue, 14 Aug 2018 23:56:07 +0000 (16:56 -0700)
committerYann Collet <cyan@fb.com>
Wed, 15 Aug 2018 20:50:49 +0000 (13:50 -0700)
1  2 
lib/compress/zstdmt_compress.c
tests/fuzzer.c
tests/roundTripCrash.c
tests/zstreamtest.c

index 74f9dc29c23ca5ef60dd6ecab3f8c1b4559e19e7,74f9dc29c23ca5ef60dd6ecab3f8c1b4559e19e7..27071ed79631f1a7332c19b1b4d7a3c3edd15957
@@@ -320,7 -320,7 +320,8 @@@ static void ZSTDMT_setNbSeq(ZSTDMT_seqP
  
  static ZSTDMT_seqPool* ZSTDMT_createSeqPool(unsigned nbWorkers, ZSTD_customMem cMem)
  {
--    ZSTDMT_seqPool* seqPool = ZSTDMT_createBufferPool(nbWorkers, cMem);
++    ZSTDMT_seqPool* const seqPool = ZSTDMT_createBufferPool(nbWorkers, cMem);
++    if (seqPool == NULL) return NULL;
      ZSTDMT_setNbSeq(seqPool, 0);
      return seqPool;
  }
diff --cc tests/fuzzer.c
index 6d57afa1621d8c059eb3d327a1e0f2e4395bef0a,6d57afa1621d8c059eb3d327a1e0f2e4395bef0a..66b33c5ee6bfa29ab5156f7d1941d064c313dec5
@@@ -179,13 -179,13 +179,9 @@@ static void FUZ_displayMallocStats(mall
          (U32)(count.totalMalloc >> 10));
  }
  
--static int FUZ_mallocTests(unsigned seed, double compressibility, unsigned part)
++static int FUZ_mallocTests_internal(unsigned seed, double compressibility, unsigned part,
++                void* inBuffer, size_t inSize, void* outBuffer, size_t outSize)
  {
--    size_t const inSize = 64 MB + 16 MB + 4 MB + 1 MB + 256 KB + 64 KB; /* 85.3 MB */
--    size_t const outSize = ZSTD_compressBound(inSize);
--    void* const inBuffer = malloc(inSize);
--    void* const outBuffer = malloc(outSize);
--
      /* test only played in verbose mode, as they are long */
      if (g_displayLevel<3) return 0;
  
      return 0;
  }
  
++static int FUZ_mallocTests(unsigned seed, double compressibility, unsigned part)
++{
++    size_t const inSize = 64 MB + 16 MB + 4 MB + 1 MB + 256 KB + 64 KB; /* 85.3 MB */
++    size_t const outSize = ZSTD_compressBound(inSize);
++    void* const inBuffer = malloc(inSize);
++    void* const outBuffer = malloc(outSize);
++    int result;
++
++    /* Create compressible noise */
++    if (!inBuffer || !outBuffer) {
++        DISPLAY("Not enough memory, aborting \n");
++        exit(1);
++    }
++
++    result = FUZ_mallocTests_internal(seed, compressibility, part,
++                    inBuffer, inSize, outBuffer, outSize);
++
++    free(inBuffer);
++    free(outBuffer);
++    return result;
++}
++
  #else
  
  static int FUZ_mallocTests(unsigned seed, double compressibility, unsigned part)
@@@ -1535,7 -1535,7 +1553,6 @@@ static int fuzzerTests(U32 seed, U32 nb
      size_t const dstBufferSize = (size_t)1<<maxSampleLog;
      size_t const cBufferSize   = ZSTD_compressBound(dstBufferSize);
      BYTE* cNoiseBuffer[5];
--    BYTE* srcBuffer;   /* jumping pointer */
      BYTE* const cBuffer = (BYTE*) malloc (cBufferSize);
      BYTE* const dstBuffer = (BYTE*) malloc (dstBufferSize);
      BYTE* const mirrorBuffer = (BYTE*) malloc (dstBufferSize);
      ZSTD_DCtx* const dctx = ZSTD_createDCtx();
      U32 result = 0;
      U32 testNb = 0;
--    U32 coreSeed = seed, lseed = 0;
++    U32 coreSeed = seed;
      UTIL_time_t const startClock = UTIL_getTime();
      U64 const maxClockSpan = maxDurationS * SEC_TO_MICRO;
      int const cLevelLimiter = bigTests ? 3 : 2;
      RDG_genBuffer(cNoiseBuffer[2], srcBufferSize, compressibility, 0., coreSeed);
      RDG_genBuffer(cNoiseBuffer[3], srcBufferSize, 0.95, 0., coreSeed);    /* highly compressible */
      RDG_genBuffer(cNoiseBuffer[4], srcBufferSize, 1.00, 0., coreSeed);    /* sparse content */
--    srcBuffer = cNoiseBuffer[2];
  
      /* catch up testNb */
      for (testNb=1; testNb < startTest; testNb++) FUZ_rand(&coreSeed);
  
      /* main test loop */
      for ( ; (testNb <= nbTests) || (UTIL_clockSpanMicro(startClock) < maxClockSpan); testNb++ ) {
++        BYTE* srcBuffer;   /* jumping pointer */
++        U32 lseed;
          size_t sampleSize, maxTestSize, totalTestSize;
          size_t cSize, totalCSize, totalGenSize;
          U64 crcOrig;
          CHECK (totalGenSize != totalTestSize, "streaming decompressed data : wrong size")
          CHECK (totalCSize != cSize, "compressed data should be fully read")
          {   U64 const crcDest = XXH64(dstBuffer, totalTestSize, 0);
--            if (crcDest!=crcOrig) {
--                size_t const errorPos = findDiff(mirrorBuffer, dstBuffer, totalTestSize);
--                CHECK (1, "streaming decompressed data corrupted : byte %u / %u  (%02X!=%02X)",
--                   (U32)errorPos, (U32)totalTestSize, dstBuffer[errorPos], mirrorBuffer[errorPos]);
--        }   }
++            CHECK(crcOrig != crcDest, "streaming decompressed data corrupted (pos %u / %u)",
++                (U32)findDiff(mirrorBuffer, dstBuffer, totalTestSize), (U32)totalTestSize);
++        }
      }   /* for ( ; (testNb <= nbTests) */
      DISPLAY("\r%u fuzzer tests completed   \n", testNb-1);
  
index 7d937fceebc01433723e9b20c780bc8c4ed3e288,7d937fceebc01433723e9b20c780bc8c4ed3e288..90afcd4b2a8be9db8d8a1b4539c04fa62dac0bb8
@@@ -212,7 -212,7 +212,7 @@@ static void loadFile(void* buffer, cons
  static void fileCheck(const char* fileName, int testCCtxParams)
  {
      size_t const fileSize = getFileSize(fileName);
--    void* buffer = malloc(fileSize);
++    void* const buffer = malloc(fileSize + !fileSize /* avoid 0 */);
      if (!buffer) {
          fprintf(stderr, "not enough memory \n");
          exit(4);
index 3d61394a7dfd8d696c59175686cb35b886d33146,3d61394a7dfd8d696c59175686cb35b886d33146..1ca1bd080a07a0150fcd0e439e2b32100eea9758
@@@ -600,7 -600,7 +600,6 @@@ static int basicUnitTests(U32 seed, dou
          size_t const initError = ZSTD_initCStream_usingCDict(zc, cdict);
          DISPLAYLEVEL(5, "ZSTD_initCStream_usingCDict result : %u ", (U32)initError);
          if (ZSTD_isError(initError)) goto _output_error;
--        cSize = 0;
          outBuff.dst = compressedBuffer;
          outBuff.size = compressedBufferSize;
          outBuff.pos = 0;
          ZSTD_CDict* const cdict = ZSTD_createCDict_advanced(dictionary.start, dictionary.filled, ZSTD_dlm_byRef, ZSTD_dct_auto, cParams, ZSTD_defaultCMem);
          size_t const initError = ZSTD_initCStream_usingCDict_advanced(zc, cdict, fParams, CNBufferSize);
          if (ZSTD_isError(initError)) goto _output_error;
--        cSize = 0;
          outBuff.dst = compressedBuffer;
          outBuff.size = compressedBufferSize;
          outBuff.pos = 0;