diff --git a/NEWS b/NEWS index cc9a59d2..06c94ce9 100644 --- a/NEWS +++ b/NEWS @@ -1,10 +1,12 @@ v0.7.3 -added : `--` separator, stating that all following arguments are file names. Suggested by Chip Turner. -added : `ZSTD_getDecompressedSize()` -added : OpenBSD target, by Juan Francisco Cantero Hurtado +New : `--` separator, stating that all following arguments are file names. Suggested by Chip Turner. +New : `ZSTD_getDecompressedSize()` +New : OpenBSD target, by Juan Francisco Cantero Hurtado +New : `examples` directory fixed : dictBuilder using HC levels, reported by Bartosz Taudul fixed : legacy support from ZSTD_decompress_usingDDict(), reported by Felix Handte -modified : removed `mem.h` dependency from `zstd.h` (experimental section) +modified : removed "mem.h" and "error_public.h" dependencies from "zstd.h" (experimental section) +modified : legacy functions no longer need magic number v0.7.2 fixed : ZSTD_decompressBlock() using multiple consecutive blocks. Reported by Greg Slazinski. diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index a43e8035..c1d9197d 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -398,12 +398,10 @@ size_t ZSTD_getFrameParams(ZSTD_frameParams* fparamsPtr, const void* src, size_t - decompressed size is not provided within frame header - frame header unknown / not supported - frame header not completely provided (`srcSize` too small) */ -unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize) { -#if ZSTD_LEGACY_SUPPORT - if (srcSize < 4) return 0; - { U32 const magic = MEM_readLE32(src); - if (ZSTD_isLegacy(magic)) return ZSTD_getDecompressedSize_legacy(src, srcSize); - } +unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize) +{ +#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT==1) + if (ZSTD_isLegacy(src, srcSize)) return ZSTD_getDecompressedSize_legacy(src, srcSize); #endif { ZSTD_frameParams fparams; size_t const frResult = ZSTD_getFrameParams(&fparams, src, srcSize); @@ -1047,10 +1045,7 @@ size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx, const void* dict, size_t dictSize) { #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT==1) - { U32 const magicNumber = MEM_readLE32(src); - if (ZSTD_isLegacy(magicNumber)) - return ZSTD_decompressLegacy(dst, dstCapacity, src, srcSize, dict, dictSize, magicNumber); - } + if (ZSTD_isLegacy(src, srcSize)) return ZSTD_decompressLegacy(dst, dstCapacity, src, srcSize, dict, dictSize); #endif ZSTD_decompressBegin_usingDict(dctx, dict, dictSize); ZSTD_checkContinuity(dctx, dst); @@ -1357,10 +1352,7 @@ ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict) { #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT==1) - { U32 const magicNumber = MEM_readLE32(src); - if (ZSTD_isLegacy(magicNumber)) - return ZSTD_decompressLegacy(dst, dstCapacity, src, srcSize, ddict->dictContent, ddict->dictContentSize, magicNumber); - } + if (ZSTD_isLegacy(src, srcSize)) return ZSTD_decompressLegacy(dst, dstCapacity, src, srcSize, ddict->dictContent, ddict->dictContentSize); #endif return ZSTD_decompress_usingPreparedDCtx(dctx, ddict->refContext, dst, dstCapacity, diff --git a/lib/legacy/zstd_legacy.h b/lib/legacy/zstd_legacy.h index 56b3e821..ab9634b3 100644 --- a/lib/legacy/zstd_legacy.h +++ b/lib/legacy/zstd_legacy.h @@ -54,8 +54,11 @@ extern "C" { @return : > 0 if supported by legacy decoder. 0 otherwise. return value is the version. */ -MEM_STATIC unsigned ZSTD_isLegacy (U32 magicNumberLE) +MEM_STATIC unsigned ZSTD_isLegacy(const void* src, size_t srcSize) { + U32 magicNumberLE; + if (srcSize<4) return 0; + magicNumberLE = MEM_readLE32(src); switch(magicNumberLE) { case ZSTDv01_magicNumberLE:return 1; @@ -73,10 +76,8 @@ MEM_STATIC unsigned long long ZSTD_getDecompressedSize_legacy(const void* src, s { if (srcSize < 4) return 0; - { U32 const magic = MEM_readLE32(src); - U32 const version = ZSTD_isLegacy(magic); - if (!version) return 0; /* not a supported legacy format */ - if (version < 5) return 0; /* no decompressed size in frame header */ + { U32 const version = ZSTD_isLegacy(src, srcSize); + if (version < 5) return 0; /* no decompressed size in frame header, or not a legacy format */ if (version==5) { ZSTDv05_parameters fParams; size_t const frResult = ZSTDv05_getFrameParams(&fParams, src, srcSize); @@ -96,20 +97,20 @@ MEM_STATIC unsigned long long ZSTD_getDecompressedSize_legacy(const void* src, s MEM_STATIC size_t ZSTD_decompressLegacy( void* dst, size_t dstCapacity, const void* src, size_t compressedSize, - const void* dict,size_t dictSize, - U32 magicNumberLE) + const void* dict,size_t dictSize) { - switch(magicNumberLE) + U32 const version = ZSTD_isLegacy(src, compressedSize); + switch(version) { - case ZSTDv01_magicNumberLE : + case 1 : return ZSTDv01_decompress(dst, dstCapacity, src, compressedSize); - case ZSTDv02_magicNumber : + case 2 : return ZSTDv02_decompress(dst, dstCapacity, src, compressedSize); - case ZSTDv03_magicNumber : + case 3 : return ZSTDv03_decompress(dst, dstCapacity, src, compressedSize); - case ZSTDv04_magicNumber : + case 4 : return ZSTDv04_decompress(dst, dstCapacity, src, compressedSize); - case ZSTDv05_MAGICNUMBER : + case 5 : { size_t result; ZSTDv05_DCtx* const zd = ZSTDv05_createDCtx(); if (zd==NULL) return ERROR(memory_allocation); @@ -117,7 +118,7 @@ MEM_STATIC size_t ZSTD_decompressLegacy( ZSTDv05_freeDCtx(zd); return result; } - case ZSTDv06_MAGICNUMBER : + case 6 : { size_t result; ZSTDv06_DCtx* const zd = ZSTDv06_createDCtx(); if (zd==NULL) return ERROR(memory_allocation); diff --git a/programs/fileio.c b/programs/fileio.c index 6081e4af..3eb8d881 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -700,7 +700,7 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* srcFileName) if (sizeCheck != toRead) EXM_THROW(31, "zstd: %s read error : cannot read header", srcFileName); { U32 const magic = MEM_readLE32(ress.srcBuffer); #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1) - if (ZSTD_isLegacy(magic)) { + if (ZSTD_isLegacy(ress.srcBuffer, 4)) { filesize += FIO_decompressLegacyFrame(dstFile, srcFile, ress.dictBuffer, ress.dictBufferSize, magic); continue; }