ext/zstdruby/libzstd/legacy/zstd_v04.c in zstd-ruby-1.1.3.0 vs ext/zstdruby/libzstd/legacy/zstd_v04.c in zstd-ruby-1.1.4.0

- old
+ new

@@ -3324,11 +3324,40 @@ } return op-ostart; } +static size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize) +{ + const BYTE* ip = (const BYTE*)src; + size_t remainingSize = srcSize; + blockProperties_t blockProperties; + /* Frame Header */ + if (srcSize < ZSTD_frameHeaderSize_min) return ERROR(srcSize_wrong); + if (MEM_readLE32(src) != ZSTD_MAGICNUMBER) return ERROR(prefix_unknown); + ip += ZSTD_frameHeaderSize_min; remainingSize -= ZSTD_frameHeaderSize_min; + + /* Loop on each block */ + while (1) + { + size_t cBlockSize = ZSTD_getcBlockSize(ip, remainingSize, &blockProperties); + if (ZSTD_isError(cBlockSize)) return cBlockSize; + + ip += ZSTD_blockHeaderSize; + remainingSize -= ZSTD_blockHeaderSize; + if (cBlockSize > remainingSize) return ERROR(srcSize_wrong); + + if (cBlockSize == 0) break; /* bt_end */ + + ip += cBlockSize; + remainingSize -= cBlockSize; + } + + return ip - (const BYTE*)src; +} + /* ****************************** * Streaming Decompression API ********************************/ static size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx) { @@ -3751,9 +3780,13 @@ ZSTD_DCtx dctx; return ZSTDv04_decompressDCtx(&dctx, dst, maxDstSize, src, srcSize); #endif } +size_t ZSTDv04_findFrameCompressedSize(const void* src, size_t srcSize) +{ + return ZSTD_findFrameCompressedSize(src, srcSize); +} size_t ZSTDv04_resetDCtx(ZSTDv04_Dctx* dctx) { return ZSTD_resetDCtx(dctx); } size_t ZSTDv04_nextSrcSizeToDecompress(ZSTDv04_Dctx* dctx) {