in csharp/src/ZStdDecompress.cs [1868:1909]
static size_t ZSTD_decompressBlock_internal(ZSTD_DCtx dctx,
void* dst, size_t dstCapacity,
void* src, size_t srcSize, int frame)
{ /* blockType == blockCompressed */
BYTE* ip = (BYTE*)src;
/* isLongOffset must be true if there are long offsets.
* Offsets are long if they are larger than 2^STREAM_ACCUMULATOR_MIN.
* We don't expect that to be the case in 64-bit mode.
* In block mode, window size is not known, so we have to be conservative. (note: but it could be evaluated from current-lowLimit)
*/
ZSTD_longOffset_e isLongOffset = (ZSTD_longOffset_e)(MEM_32bits() && (frame == 0 || dctx.fParams.windowSize > ((U64)1 << (int)STREAM_ACCUMULATOR_MIN)) ? 1 : 0);
if (srcSize >= ZSTD_BLOCKSIZE_MAX) return ERROR(Error.srcSize_wrong);
/* Decode literals section */
{
size_t litCSize = DecodeLiteralsBlock(dctx, src, srcSize);
if (IsError(litCSize)) return litCSize;
ip += litCSize;
srcSize -= litCSize;
}
/* Build Decoding Tables */
{
int nbSeq;
size_t seqHSize = DecodeSeqHeaders(dctx, &nbSeq, ip, srcSize);
if (IsError(seqHSize)) return seqHSize;
ip += seqHSize;
srcSize -= seqHSize;
if ((frame == 0 || dctx.fParams.windowSize > (1 << 24))
&& (nbSeq > 0))
{ /* could probably use a larger nbSeq limit */
U32 shareLongOffsets = GetLongOffsetsShare(dctx.OFTptr);
U32 minShare = MEM_64bits() ? (U32)7 : 20; /* heuristic values, correspond to 2.73% and 7.81% */
if (shareLongOffsets >= minShare)
return DecompressSequencesLong(dctx, dst, dstCapacity, ip, srcSize, nbSeq, isLongOffset);
}
return DecompressSequences(dctx, dst, dstCapacity, ip, srcSize, nbSeq, isLongOffset);
}
}