ReactOS  0.4.14-dev-815-ge410a12
zstd_decompress.c File Reference
#include <string.h>
#include "compiler.h"
#include "cpu.h"
#include "mem.h"
#include "fse.h"
#include "huf.h"
#include "zstd_internal.h"
Include dependency graph for zstd_decompress.c:

Go to the source code of this file.

Classes

struct  ZSTD_seqSymbol_header
 
struct  ZSTD_seqSymbol
 
struct  ZSTD_entropyDTables_t
 
struct  ZSTD_DCtx_s
 
struct  seq_t
 
struct  ZSTD_fseState
 
struct  seqState_t
 
struct  ZSTD_DDict_s
 

Macros

#define ZSTD_HEAPMODE   1
 
#define ZSTD_LEGACY_SUPPORT   0
 
#define ZSTD_MAXWINDOWSIZE_DEFAULT   (((U32)1 << ZSTD_WINDOWLOG_DEFAULTMAX) + 1)
 
#define ZSTD_NO_FORWARD_PROGRESS_MAX   16
 
#define FSE_STATIC_LINKING_ONLY
 
#define HUF_STATIC_LINKING_ONLY
 
#define ZSTD_isError   ERR_isError /* for inlining */
 
#define FSE_isError   ERR_isError
 
#define HUF_isError   ERR_isError
 
#define SEQSYMBOL_TABLE_SIZE(log)   (1 + (1 << (log)))
 
#define LONG_OFFSETS_MAX_EXTRA_BITS_32
 
#define STORED_SEQS   4
 
#define STOSEQ_MASK   (STORED_SEQS-1)
 
#define ADVANCED_SEQS   4
 

Typedefs

typedef size_t(* ZSTD_decompressSequences_t) (ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
 

Enumerations

enum  ZSTD_dStage {
  ZSTDds_getFrameHeaderSize, ZSTDds_decodeFrameHeader, ZSTDds_decodeBlockHeader, ZSTDds_decompressBlock,
  ZSTDds_decompressLastBlock, ZSTDds_checkChecksum, ZSTDds_decodeSkippableHeader, ZSTDds_skipFrame
}
 
enum  ZSTD_dStreamStage {
  zdss_init =0, zdss_loadHeader, zdss_read, zdss_load,
  zdss_flush
}
 
enum  ZSTD_longOffset_e { ZSTD_lo_isRegularOffset, ZSTD_lo_isLongOffset =1 }
 

Functions

static const voidZSTD_DDictDictContent (const ZSTD_DDict *ddict)
 
static size_t ZSTD_DDictDictSize (const ZSTD_DDict *ddict)
 
static void ZSTD_copy4 (void *dst, const void *src)
 
size_t ZSTD_sizeof_DCtx (const ZSTD_DCtx *dctx)
 
size_t ZSTD_estimateDCtxSize (void)
 
static size_t ZSTD_startingInputLength (ZSTD_format_e format)
 
static void ZSTD_initDCtx_internal (ZSTD_DCtx *dctx)
 
ZSTD_DCtxZSTD_initStaticDCtx (void *workspace, size_t workspaceSize)
 
ZSTD_DCtxZSTD_createDCtx_advanced (ZSTD_customMem customMem)
 
ZSTD_DCtxZSTD_createDCtx (void)
 
size_t ZSTD_freeDCtx (ZSTD_DCtx *dctx)
 
void ZSTD_copyDCtx (ZSTD_DCtx *dstDCtx, const ZSTD_DCtx *srcDCtx)
 
unsigned ZSTD_isFrame (const void *buffer, size_t size)
 
static size_t ZSTD_frameHeaderSize_internal (const void *src, size_t srcSize, ZSTD_format_e format)
 
size_t ZSTD_frameHeaderSize (const void *src, size_t srcSize)
 
size_t ZSTD_getFrameHeader_advanced (ZSTD_frameHeader *zfhPtr, const void *src, size_t srcSize, ZSTD_format_e format)
 
size_t ZSTD_getFrameHeader (ZSTD_frameHeader *zfhPtr, const void *src, size_t srcSize)
 
unsigned long long ZSTD_getFrameContentSize (const void *src, size_t srcSize)
 
unsigned long long ZSTD_findDecompressedSize (const void *src, size_t srcSize)
 
unsigned long long ZSTD_getDecompressedSize (const void *src, size_t srcSize)
 
static size_t ZSTD_decodeFrameHeader (ZSTD_DCtx *dctx, const void *src, size_t headerSize)
 
size_t ZSTD_getcBlockSize (const void *src, size_t srcSize, blockProperties_t *bpPtr)
 
static size_t ZSTD_copyRawBlock (void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
static size_t ZSTD_setRleBlock (void *dst, size_t dstCapacity, const void *src, size_t srcSize, size_t regenSize)
 
size_t ZSTD_decodeLiteralsBlock (ZSTD_DCtx *dctx, const void *src, size_t srcSize)
 
static void ZSTD_buildSeqTable_rle (ZSTD_seqSymbol *dt, U32 baseValue, U32 nbAddBits)
 
static void ZSTD_buildFSETable (ZSTD_seqSymbol *dt, const short *normalizedCounter, unsigned maxSymbolValue, const U32 *baseValue, const U32 *nbAdditionalBits, unsigned tableLog)
 
static size_t ZSTD_buildSeqTable (ZSTD_seqSymbol *DTableSpace, const ZSTD_seqSymbol **DTablePtr, symbolEncodingType_e type, U32 max, U32 maxLog, const void *src, size_t srcSize, const U32 *baseValue, const U32 *nbAdditionalBits, const ZSTD_seqSymbol *defaultTable, U32 flagRepeatTable, int ddictIsCold, int nbSeq)
 
size_t ZSTD_decodeSeqHeaders (ZSTD_DCtx *dctx, int *nbSeqPtr, const void *src, size_t srcSize)
 
FORCE_NOINLINE size_t ZSTD_execSequenceLast7 (BYTE *op, BYTE *const oend, seq_t sequence, const BYTE **litPtr, const BYTE *const litLimit, const BYTE *const base, const BYTE *const vBase, const BYTE *const dictEnd)
 
HINT_INLINE size_t ZSTD_execSequence (BYTE *op, BYTE *const oend, seq_t sequence, const BYTE **litPtr, const BYTE *const litLimit, const BYTE *const prefixStart, const BYTE *const virtualStart, const BYTE *const dictEnd)
 
HINT_INLINE size_t ZSTD_execSequenceLong (BYTE *op, BYTE *const oend, seq_t sequence, const BYTE **litPtr, const BYTE *const litLimit, const BYTE *const prefixStart, const BYTE *const dictStart, const BYTE *const dictEnd)
 
static void ZSTD_initFseState (ZSTD_fseState *DStatePtr, BIT_DStream_t *bitD, const ZSTD_seqSymbol *dt)
 
FORCE_INLINE_TEMPLATE void ZSTD_updateFseState (ZSTD_fseState *DStatePtr, BIT_DStream_t *bitD)
 
FORCE_INLINE_TEMPLATE seq_t ZSTD_decodeSequence (seqState_t *seqState, const ZSTD_longOffset_e longOffsets)
 
FORCE_INLINE_TEMPLATE size_t ZSTD_decompressSequences_body (ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
 
static size_t ZSTD_decompressSequences_default (ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
 
FORCE_INLINE_TEMPLATE seq_t ZSTD_decodeSequenceLong (seqState_t *seqState, ZSTD_longOffset_e const longOffsets)
 
FORCE_INLINE_TEMPLATE size_t ZSTD_decompressSequencesLong_body (ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
 
static size_t ZSTD_decompressSequencesLong_default (ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
 
static size_t ZSTD_decompressSequences (ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
 
static size_t ZSTD_decompressSequencesLong (ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
 
static unsigned ZSTD_getLongOffsetsShare (const ZSTD_seqSymbol *offTable)
 
static size_t ZSTD_decompressBlock_internal (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const int frame)
 
static void ZSTD_checkContinuity (ZSTD_DCtx *dctx, const void *dst)
 
size_t ZSTD_decompressBlock (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
ZSTDLIB_API size_t ZSTD_insertBlock (ZSTD_DCtx *dctx, const void *blockStart, size_t blockSize)
 
static size_t ZSTD_generateNxBytes (void *dst, size_t dstCapacity, BYTE value, size_t length)
 
size_t ZSTD_findFrameCompressedSize (const void *src, size_t srcSize)
 
static size_t ZSTD_decompressFrame (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void **srcPtr, size_t *srcSizePtr)
 
static size_t ZSTD_decompressMultiFrame (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, const ZSTD_DDict *ddict)
 
size_t ZSTD_decompress_usingDict (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize)
 
size_t ZSTD_decompressDCtx (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
size_t ZSTD_decompress (void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
size_t ZSTD_nextSrcSizeToDecompress (ZSTD_DCtx *dctx)
 
ZSTD_nextInputType_e ZSTD_nextInputType (ZSTD_DCtx *dctx)
 
static int ZSTD_isSkipFrame (ZSTD_DCtx *dctx)
 
size_t ZSTD_decompressContinue (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
static size_t ZSTD_refDictContent (ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
 
static size_t ZSTD_loadEntropy (ZSTD_entropyDTables_t *entropy, const void *const dict, size_t const dictSize)
 
static size_t ZSTD_decompress_insertDictionary (ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
 
size_t ZSTD_decompressBegin (ZSTD_DCtx *dctx)
 
size_t ZSTD_decompressBegin_usingDict (ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
 
size_t ZSTD_decompressBegin_usingDDict (ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
 
static size_t ZSTD_loadEntropy_inDDict (ZSTD_DDict *ddict, ZSTD_dictContentType_e dictContentType)
 
static size_t ZSTD_initDDict_internal (ZSTD_DDict *ddict, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
 
ZSTD_DDictZSTD_createDDict_advanced (const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_customMem customMem)
 
ZSTD_DDictZSTD_createDDict (const void *dict, size_t dictSize)
 
ZSTD_DDictZSTD_createDDict_byReference (const void *dictBuffer, size_t dictSize)
 
const ZSTD_DDictZSTD_initStaticDDict (void *sBuffer, size_t sBufferSize, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
 
size_t ZSTD_freeDDict (ZSTD_DDict *ddict)
 
size_t ZSTD_estimateDDictSize (size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod)
 
size_t ZSTD_sizeof_DDict (const ZSTD_DDict *ddict)
 
unsigned ZSTD_getDictID_fromDict (const void *dict, size_t dictSize)
 
unsigned ZSTD_getDictID_fromDDict (const ZSTD_DDict *ddict)
 
unsigned ZSTD_getDictID_fromFrame (const void *src, size_t srcSize)
 
size_t ZSTD_decompress_usingDDict (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_DDict *ddict)
 
ZSTD_DStreamZSTD_createDStream (void)
 
ZSTD_DStreamZSTD_initStaticDStream (void *workspace, size_t workspaceSize)
 
ZSTD_DStreamZSTD_createDStream_advanced (ZSTD_customMem customMem)
 
size_t ZSTD_freeDStream (ZSTD_DStream *zds)
 
size_t ZSTD_DStreamInSize (void)
 
size_t ZSTD_DStreamOutSize (void)
 
size_t ZSTD_DCtx_loadDictionary_advanced (ZSTD_DCtx *dctx, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
 
size_t ZSTD_DCtx_loadDictionary_byReference (ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
 
size_t ZSTD_DCtx_loadDictionary (ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
 
size_t ZSTD_DCtx_refPrefix_advanced (ZSTD_DCtx *dctx, const void *prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)
 
size_t ZSTD_DCtx_refPrefix (ZSTD_DCtx *dctx, const void *prefix, size_t prefixSize)
 
size_t ZSTD_initDStream_usingDict (ZSTD_DStream *zds, const void *dict, size_t dictSize)
 
size_t ZSTD_initDStream (ZSTD_DStream *zds)
 
size_t ZSTD_initDStream_usingDDict (ZSTD_DStream *dctx, const ZSTD_DDict *ddict)
 
size_t ZSTD_resetDStream (ZSTD_DStream *dctx)
 
size_t ZSTD_setDStreamParameter (ZSTD_DStream *dctx, ZSTD_DStreamParameter_e paramType, unsigned paramValue)
 
size_t ZSTD_DCtx_refDDict (ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
 
size_t ZSTD_DCtx_setMaxWindowSize (ZSTD_DCtx *dctx, size_t maxWindowSize)
 
size_t ZSTD_DCtx_setFormat (ZSTD_DCtx *dctx, ZSTD_format_e format)
 
size_t ZSTD_sizeof_DStream (const ZSTD_DStream *dctx)
 
size_t ZSTD_decodingBufferSize_min (unsigned long long windowSize, unsigned long long frameContentSize)
 
size_t ZSTD_estimateDStreamSize (size_t windowSize)
 
size_t ZSTD_estimateDStreamSize_fromFrame (const void *src, size_t srcSize)
 
MEM_STATIC size_t ZSTD_limitCopy (void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
size_t ZSTD_decompressStream (ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
 
size_t ZSTD_decompress_generic (ZSTD_DCtx *dctx, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
 
size_t ZSTD_decompress_generic_simpleArgs (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, size_t *dstPos, const void *src, size_t srcSize, size_t *srcPos)
 
void ZSTD_DCtx_reset (ZSTD_DCtx *dctx)
 

Variables

static const ZSTD_seqSymbol LL_defaultDTable [(1<< LL_DEFAULTNORMLOG)+1]
 
static const ZSTD_seqSymbol OF_defaultDTable [(1<< OF_DEFAULTNORMLOG)+1]
 
static const ZSTD_seqSymbol ML_defaultDTable [(1<< ML_DEFAULTNORMLOG)+1]
 
static const U32 LL_base [MaxLL+1]
 
static const U32 OF_base [MaxOff+1]
 
static const U32 OF_bits [MaxOff+1]
 
static const U32 ML_base [MaxML+1]
 

Macro Definition Documentation

◆ ADVANCED_SEQS

#define ADVANCED_SEQS   4

◆ FSE_isError

#define FSE_isError   ERR_isError

Definition at line 80 of file zstd_decompress.c.

◆ FSE_STATIC_LINKING_ONLY

#define FSE_STATIC_LINKING_ONLY

Definition at line 62 of file zstd_decompress.c.

◆ HUF_isError

#define HUF_isError   ERR_isError

Definition at line 81 of file zstd_decompress.c.

◆ HUF_STATIC_LINKING_ONLY

#define HUF_STATIC_LINKING_ONLY

Definition at line 64 of file zstd_decompress.c.

◆ LONG_OFFSETS_MAX_EXTRA_BITS_32

#define LONG_OFFSETS_MAX_EXTRA_BITS_32
Value:
(ZSTD_WINDOWLOG_MAX_32 > STREAM_ACCUMULATOR_MIN_32 \
? ZSTD_WINDOWLOG_MAX_32 - STREAM_ACCUMULATOR_MIN_32 \
: 0)
#define STREAM_ACCUMULATOR_MIN_32
Definition: bitstream.h:62

Definition at line 1318 of file zstd_decompress.c.

◆ SEQSYMBOL_TABLE_SIZE

#define SEQSYMBOL_TABLE_SIZE (   log)    (1 + (1 << (log)))

Definition at line 114 of file zstd_decompress.c.

◆ STORED_SEQS

#define STORED_SEQS   4

◆ STOSEQ_MASK

#define STOSEQ_MASK   (STORED_SEQS-1)

◆ ZSTD_HEAPMODE

#define ZSTD_HEAPMODE   1

HEAPMODE : Select how default decompression function ZSTD_decompress() allocates its context, on stack (0), or into heap (1, default; requires malloc()). Note that functions with explicit context such as ZSTD_decompressDCtx() are unaffected.

Definition at line 22 of file zstd_decompress.c.

◆ ZSTD_isError

#define ZSTD_isError   ERR_isError /* for inlining */

Definition at line 79 of file zstd_decompress.c.

◆ ZSTD_LEGACY_SUPPORT

#define ZSTD_LEGACY_SUPPORT   0

LEGACY_SUPPORT : if set to 1+, ZSTD_decompress() can decode older formats (v0.1+)

Definition at line 30 of file zstd_decompress.c.

◆ ZSTD_MAXWINDOWSIZE_DEFAULT

#define ZSTD_MAXWINDOWSIZE_DEFAULT   (((U32)1 << ZSTD_WINDOWLOG_DEFAULTMAX) + 1)

MAXWINDOWSIZE_DEFAULT : maximum window size accepted by DStream by default. Frames requiring more memory will be rejected. It's possible to set a different limit using ZSTD_DCtx_setMaxWindowSize().

Definition at line 40 of file zstd_decompress.c.

◆ ZSTD_NO_FORWARD_PROGRESS_MAX

#define ZSTD_NO_FORWARD_PROGRESS_MAX   16

NO_FORWARD_PROGRESS_MAX : maximum allowed nb of calls to ZSTD_decompressStream() and ZSTD_decompress_generic() without any forward progress (defined as: no byte read from input, and no byte flushed to output) before triggering an error.

Definition at line 51 of file zstd_decompress.c.

Typedef Documentation

◆ ZSTD_decompressSequences_t

typedef size_t(* ZSTD_decompressSequences_t) (ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)

Definition at line 1657 of file zstd_decompress.c.

Enumeration Type Documentation

◆ ZSTD_dStage

Enumerator
ZSTDds_getFrameHeaderSize 
ZSTDds_decodeFrameHeader 
ZSTDds_decodeBlockHeader 
ZSTDds_decompressBlock 
ZSTDds_decompressLastBlock 
ZSTDds_checkChecksum 
ZSTDds_decodeSkippableHeader 
ZSTDds_skipFrame 

Definition at line 93 of file zstd_decompress.c.

◆ ZSTD_dStreamStage

Enumerator
zdss_init 
zdss_loadHeader 
zdss_read 
zdss_load 
zdss_flush 

Definition at line 98 of file zstd_decompress.c.

◆ ZSTD_longOffset_e

Enumerator
ZSTD_lo_isRegularOffset 
ZSTD_lo_isLongOffset 

Definition at line 1323 of file zstd_decompress.c.

Function Documentation

◆ ZSTD_buildFSETable()

static void ZSTD_buildFSETable ( ZSTD_seqSymbol dt,
const short normalizedCounter,
unsigned  maxSymbolValue,
const U32 baseValue,
const U32 nbAdditionalBits,
unsigned  tableLog 
)
static

Definition at line 839 of file zstd_decompress.c.

843 {
844  ZSTD_seqSymbol* const tableDecode = dt+1;
845  U16 symbolNext[MaxSeq+1];
846 
847  U32 const maxSV1 = maxSymbolValue + 1;
848  U32 const tableSize = 1 << tableLog;
849  U32 highThreshold = tableSize-1;
850 
851  /* Sanity Checks */
852  assert(maxSymbolValue <= MaxSeq);
853  assert(tableLog <= MaxFSELog);
854 
855  /* Init, lay down lowprob symbols */
856  { ZSTD_seqSymbol_header DTableH;
857  DTableH.tableLog = tableLog;
858  DTableH.fastMode = 1;
859  { S16 const largeLimit= (S16)(1 << (tableLog-1));
860  U32 s;
861  for (s=0; s<maxSV1; s++) {
862  if (normalizedCounter[s]==-1) {
863  tableDecode[highThreshold--].baseValue = s;
864  symbolNext[s] = 1;
865  } else {
866  if (normalizedCounter[s] >= largeLimit) DTableH.fastMode=0;
867  symbolNext[s] = normalizedCounter[s];
868  } } }
869  memcpy(dt, &DTableH, sizeof(DTableH));
870  }
871 
872  /* Spread symbols */
873  { U32 const tableMask = tableSize-1;
874  U32 const step = FSE_TABLESTEP(tableSize);
875  U32 s, position = 0;
876  for (s=0; s<maxSV1; s++) {
877  int i;
878  for (i=0; i<normalizedCounter[s]; i++) {
879  tableDecode[position].baseValue = s;
880  position = (position + step) & tableMask;
881  while (position > highThreshold) position = (position + step) & tableMask; /* lowprob area */
882  } }
883  assert(position == 0); /* position must reach all cells once, otherwise normalizedCounter is incorrect */
884  }
885 
886  /* Build Decoding table */
887  { U32 u;
888  for (u=0; u<tableSize; u++) {
889  U32 const symbol = tableDecode[u].baseValue;
890  U32 const nextState = symbolNext[symbol]++;
891  tableDecode[u].nbBits = (BYTE) (tableLog - BIT_highbit32(nextState) );
892  tableDecode[u].nextState = (U16) ( (nextState << tableDecode[u].nbBits) - tableSize);
893  assert(nbAdditionalBits[symbol] < 255);
894  tableDecode[u].nbAdditionalBits = (BYTE)nbAdditionalBits[symbol];
895  tableDecode[u].baseValue = baseValue[symbol];
896  } }
897 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
unsigned short U16
Definition: mem.h:72
#define MaxSeq
#define MaxFSELog
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
MEM_STATIC unsigned BIT_highbit32(U32 val)
Definition: bitstream.h:156
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
GLdouble s
Definition: gl.h:2039
signed short S16
Definition: mem.h:73

Referenced by ZSTD_buildSeqTable(), and ZSTD_loadEntropy().

◆ ZSTD_buildSeqTable()

static size_t ZSTD_buildSeqTable ( ZSTD_seqSymbol DTableSpace,
const ZSTD_seqSymbol **  DTablePtr,
symbolEncodingType_e  type,
U32  max,
U32  maxLog,
const void src,
size_t  srcSize,
const U32 baseValue,
const U32 nbAdditionalBits,
const ZSTD_seqSymbol defaultTable,
U32  flagRepeatTable,
int  ddictIsCold,
int  nbSeq 
)
static

ZSTD_buildSeqTable() :

Returns
: nb bytes read from src, or an error code if it fails

Definition at line 903 of file zstd_decompress.c.

909 {
910  switch(type)
911  {
912  case set_rle :
913  if (!srcSize) return ERROR(srcSize_wrong);
914  if ( (*(const BYTE*)src) > max) return ERROR(corruption_detected);
915  { U32 const symbol = *(const BYTE*)src;
916  U32 const baseline = baseValue[symbol];
917  U32 const nbBits = nbAdditionalBits[symbol];
918  ZSTD_buildSeqTable_rle(DTableSpace, baseline, nbBits);
919  }
920  *DTablePtr = DTableSpace;
921  return 1;
922  case set_basic :
923  *DTablePtr = defaultTable;
924  return 0;
925  case set_repeat:
926  if (!flagRepeatTable) return ERROR(corruption_detected);
927  /* prefetch FSE table if used */
928  if (ddictIsCold && (nbSeq > 24 /* heuristic */)) {
929  const void* const pStart = *DTablePtr;
930  size_t const pSize = sizeof(ZSTD_seqSymbol) * (SEQSYMBOL_TABLE_SIZE(maxLog));
931  PREFETCH_AREA(pStart, pSize);
932  }
933  return 0;
934  case set_compressed :
935  { U32 tableLog;
936  S16 norm[MaxSeq+1];
937  size_t const headerSize = FSE_readNCount(norm, &max, &tableLog, src, srcSize);
938  if (FSE_isError(headerSize)) return ERROR(corruption_detected);
939  if (tableLog > maxLog) return ERROR(corruption_detected);
940  ZSTD_buildFSETable(DTableSpace, norm, max, baseValue, nbAdditionalBits, tableLog);
941  *DTablePtr = DTableSpace;
942  return headerSize;
943  }
944  default : /* impossible */
945  assert(0);
946  return ERROR(GENERIC);
947  }
948 }
#define max(a, b)
Definition: svc.c:63
#define SEQSYMBOL_TABLE_SIZE(log)
#define MaxSeq
_Tp _STLP_CALL norm(const complex< _Tp > &__z)
Definition: _complex.h:741
#define ERROR(name)
Definition: error_private.h:53
size_t FSE_readNCount(short *normalizedCounter, unsigned *maxSVPtr, unsigned *tableLogPtr, const void *headerBuffer, size_t hbSize)
unsigned int U32
Definition: mem.h:77
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define assert(x)
Definition: debug.h:53
#define PREFETCH_AREA(p, s)
Definition: compiler.h:114
static void ZSTD_buildFSETable(ZSTD_seqSymbol *dt, const short *normalizedCounter, unsigned maxSymbolValue, const U32 *baseValue, const U32 *nbAdditionalBits, unsigned tableLog)
static void ZSTD_buildSeqTable_rle(ZSTD_seqSymbol *dt, U32 baseValue, U32 nbAddBits)
#define FSE_isError
unsigned char BYTE
Definition: mem.h:68
GLenum src
Definition: glext.h:6340
signed short S16
Definition: mem.h:73

Referenced by ZSTD_decodeSeqHeaders().

◆ ZSTD_buildSeqTable_rle()

static void ZSTD_buildSeqTable_rle ( ZSTD_seqSymbol dt,
U32  baseValue,
U32  nbAddBits 
)
static

Definition at line 819 of file zstd_decompress.c.

820 {
821  void* ptr = dt;
823  ZSTD_seqSymbol* const cell = dt + 1;
824 
825  DTableH->tableLog = 0;
826  DTableH->fastMode = 0;
827 
828  cell->nbBits = 0;
829  cell->nextState = 0;
830  assert(nbAddBits < 255);
831  cell->nbAdditionalBits = (BYTE)nbAddBits;
832  cell->baseValue = baseValue;
833 }
#define assert(x)
Definition: debug.h:53
static PVOID ptr
Definition: dispmode.c:27
unsigned char BYTE
Definition: mem.h:68

Referenced by ZSTD_buildSeqTable().

◆ ZSTD_checkContinuity()

static void ZSTD_checkContinuity ( ZSTD_DCtx dctx,
const void dst 
)
static

Definition at line 1759 of file zstd_decompress.c.

1760 {
1761  if (dst != dctx->previousDstEnd) { /* not contiguous */
1762  dctx->dictEnd = dctx->previousDstEnd;
1763  dctx->virtualStart = (const char*)dst - ((const char*)(dctx->previousDstEnd) - (const char*)(dctx->prefixStart));
1764  dctx->prefixStart = dst;
1765  dctx->previousDstEnd = dst;
1766  }
1767 }
const void * previousDstEnd
const void * dictEnd
const void * virtualStart
const void * prefixStart
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_decompressBlock(), ZSTD_decompressContinue(), ZSTD_decompressMultiFrame(), and ZSTD_insertBlock().

◆ ZSTD_copy4()

static void ZSTD_copy4 ( void dst,
const void src 
)
static

Definition at line 87 of file zstd_decompress.c.

87 { memcpy(dst, src, 4); }
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_execSequence(), and ZSTD_execSequenceLong().

◆ ZSTD_copyDCtx()

void ZSTD_copyDCtx ( ZSTD_DCtx dstDCtx,
const ZSTD_DCtx srcDCtx 
)

Definition at line 272 of file zstd_decompress.c.

273 {
274  size_t const toCopy = (size_t)((char*)(&dstDCtx->inBuff) - (char*)dstDCtx);
275  memcpy(dstDCtx, srcDCtx, toCopy); /* no need to copy workspace */
276 }
__kernel_size_t size_t
Definition: linux.h:237
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ ZSTD_copyRawBlock()

static size_t ZSTD_copyRawBlock ( void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize 
)
static

Definition at line 551 of file zstd_decompress.c.

553 {
554  if (dst==NULL) return ERROR(dstSize_tooSmall);
555  if (srcSize > dstCapacity) return ERROR(dstSize_tooSmall);
556  memcpy(dst, src, srcSize);
557  return srcSize;
558 }
#define ERROR(name)
Definition: error_private.h:53
smooth NULL
Definition: ftsmooth.c:416
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_decompressContinue(), and ZSTD_decompressFrame().

◆ ZSTD_createDCtx()

ZSTD_DCtx* ZSTD_createDCtx ( void  )

Definition at line 247 of file zstd_decompress.c.

248 {
249  DEBUGLOG(3, "ZSTD_createDCtx");
250  return ZSTD_createDCtx_advanced(ZSTD_defaultCMem);
251 }
#define DEBUGLOG(l,...)
Definition: debug.h:115
ZSTD_DCtx * ZSTD_createDCtx_advanced(ZSTD_customMem customMem)

Referenced by ZSTD_decompress().

◆ ZSTD_createDCtx_advanced()

ZSTD_DCtx* ZSTD_createDCtx_advanced ( ZSTD_customMem  customMem)

Definition at line 235 of file zstd_decompress.c.

236 {
237  if (!customMem.customAlloc ^ !customMem.customFree) return NULL;
238 
239  { ZSTD_DCtx* const dctx = (ZSTD_DCtx*)ZSTD_malloc(sizeof(*dctx), customMem);
240  if (!dctx) return NULL;
241  dctx->customMem = customMem;
243  return dctx;
244  }
245 }
smooth NULL
Definition: ftsmooth.c:416
ZSTD_customMem customMem
void * ZSTD_malloc(size_t size, ZSTD_customMem customMem)
Definition: zstd_common.c:54
static void ZSTD_initDCtx_internal(ZSTD_DCtx *dctx)

Referenced by ZSTD_createDCtx(), and ZSTD_createDStream_advanced().

◆ ZSTD_createDDict()

ZSTD_DDict* ZSTD_createDDict ( const void dict,
size_t  dictSize 
)

ZSTD_createDDict() : Create a digested dictionary, to start decompression without startup delay. dict content is copied inside DDict. Consequently, dict can be released after ZSTD_DDict creation

Definition at line 2504 of file zstd_decompress.c.

2505 {
2506  ZSTD_customMem const allocator = { NULL, NULL, NULL };
2507  return ZSTD_createDDict_advanced(dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto, allocator);
2508 }
smooth NULL
Definition: ftsmooth.c:416
ZSTD_DDict * ZSTD_createDDict_advanced(const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_customMem customMem)

◆ ZSTD_createDDict_advanced()

ZSTD_DDict* ZSTD_createDDict_advanced ( const void dict,
size_t  dictSize,
ZSTD_dictLoadMethod_e  dictLoadMethod,
ZSTD_dictContentType_e  dictContentType,
ZSTD_customMem  customMem 
)

Definition at line 2479 of file zstd_decompress.c.

2483 {
2484  if (!customMem.customAlloc ^ !customMem.customFree) return NULL;
2485 
2486  { ZSTD_DDict* const ddict = (ZSTD_DDict*) ZSTD_malloc(sizeof(ZSTD_DDict), customMem);
2487  if (ddict == NULL) return NULL;
2488  ddict->cMem = customMem;
2489  { size_t const initResult = ZSTD_initDDict_internal(ddict,
2490  dict, dictSize,
2491  dictLoadMethod, dictContentType);
2492  if (ZSTD_isError(initResult)) {
2493  ZSTD_freeDDict(ddict);
2494  return NULL;
2495  } }
2496  return ddict;
2497  }
2498 }
smooth NULL
Definition: ftsmooth.c:416
ZSTD_customMem cMem
void * ZSTD_malloc(size_t size, ZSTD_customMem customMem)
Definition: zstd_common.c:54
#define ZSTD_isError
static size_t ZSTD_initDDict_internal(ZSTD_DDict *ddict, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
size_t ZSTD_freeDDict(ZSTD_DDict *ddict)

Referenced by ZSTD_createDDict(), ZSTD_createDDict_byReference(), and ZSTD_DCtx_loadDictionary_advanced().

◆ ZSTD_createDDict_byReference()

ZSTD_DDict* ZSTD_createDDict_byReference ( const void dictBuffer,
size_t  dictSize 
)

ZSTD_createDDict_byReference() : Create a digested dictionary, to start decompression without startup delay. Dictionary content is simply referenced, it will be accessed during decompression. Warning : dictBuffer must outlive DDict (DDict must be freed before dictBuffer)

Definition at line 2514 of file zstd_decompress.c.

2515 {
2516  ZSTD_customMem const allocator = { NULL, NULL, NULL };
2517  return ZSTD_createDDict_advanced(dictBuffer, dictSize, ZSTD_dlm_byRef, ZSTD_dct_auto, allocator);
2518 }
smooth NULL
Definition: ftsmooth.c:416
ZSTD_DDict * ZSTD_createDDict_advanced(const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_customMem customMem)

◆ ZSTD_createDStream()

ZSTD_DStream* ZSTD_createDStream ( void  )

Definition at line 2632 of file zstd_decompress.c.

2633 {
2634  DEBUGLOG(3, "ZSTD_createDStream");
2635  return ZSTD_createDStream_advanced(ZSTD_defaultCMem);
2636 }
#define DEBUGLOG(l,...)
Definition: debug.h:115
ZSTD_DStream * ZSTD_createDStream_advanced(ZSTD_customMem customMem)

◆ ZSTD_createDStream_advanced()

ZSTD_DStream* ZSTD_createDStream_advanced ( ZSTD_customMem  customMem)

Definition at line 2643 of file zstd_decompress.c.

2644 {
2645  return ZSTD_createDCtx_advanced(customMem);
2646 }
ZSTD_DCtx * ZSTD_createDCtx_advanced(ZSTD_customMem customMem)

Referenced by ZSTD_createDStream(), and zstd_decompress().

◆ ZSTD_DCtx_loadDictionary()

size_t ZSTD_DCtx_loadDictionary ( ZSTD_DCtx dctx,
const void dict,
size_t  dictSize 
)

Definition at line 2681 of file zstd_decompress.c.

2682 {
2683  return ZSTD_DCtx_loadDictionary_advanced(dctx, dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto);
2684 }
size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx *dctx, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)

Referenced by ZSTD_initDStream_usingDict().

◆ ZSTD_DCtx_loadDictionary_advanced()

size_t ZSTD_DCtx_loadDictionary_advanced ( ZSTD_DCtx dctx,
const void dict,
size_t  dictSize,
ZSTD_dictLoadMethod_e  dictLoadMethod,
ZSTD_dictContentType_e  dictContentType 
)

Definition at line 2659 of file zstd_decompress.c.

2663 {
2664  if (dctx->streamStage != zdss_init) return ERROR(stage_wrong);
2665  ZSTD_freeDDict(dctx->ddictLocal);
2666  if (dict && dictSize >= 8) {
2667  dctx->ddictLocal = ZSTD_createDDict_advanced(dict, dictSize, dictLoadMethod, dictContentType, dctx->customMem);
2668  if (dctx->ddictLocal == NULL) return ERROR(memory_allocation);
2669  } else {
2670  dctx->ddictLocal = NULL;
2671  }
2672  dctx->ddict = dctx->ddictLocal;
2673  return 0;
2674 }
#define ERROR(name)
Definition: error_private.h:53
ZSTD_dStreamStage streamStage
smooth NULL
Definition: ftsmooth.c:416
ZSTD_customMem customMem
const ZSTD_DDict * ddict
ZSTD_DDict * ddictLocal
ZSTD_DDict * ZSTD_createDDict_advanced(const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_customMem customMem)
size_t ZSTD_freeDDict(ZSTD_DDict *ddict)

Referenced by ZSTD_DCtx_loadDictionary(), ZSTD_DCtx_loadDictionary_byReference(), and ZSTD_DCtx_refPrefix_advanced().

◆ ZSTD_DCtx_loadDictionary_byReference()

size_t ZSTD_DCtx_loadDictionary_byReference ( ZSTD_DCtx dctx,
const void dict,
size_t  dictSize 
)

Definition at line 2676 of file zstd_decompress.c.

2677 {
2678  return ZSTD_DCtx_loadDictionary_advanced(dctx, dict, dictSize, ZSTD_dlm_byRef, ZSTD_dct_auto);
2679 }
size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx *dctx, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)

◆ ZSTD_DCtx_refDDict()

size_t ZSTD_DCtx_refDDict ( ZSTD_DCtx dctx,
const ZSTD_DDict ddict 
)

Definition at line 2754 of file zstd_decompress.c.

2755 {
2756  if (dctx->streamStage != zdss_init) return ERROR(stage_wrong);
2757  dctx->ddict = ddict;
2758  return 0;
2759 }
#define ERROR(name)
Definition: error_private.h:53
ZSTD_dStreamStage streamStage
const ZSTD_DDict * ddict

◆ ZSTD_DCtx_refPrefix()

size_t ZSTD_DCtx_refPrefix ( ZSTD_DCtx dctx,
const void prefix,
size_t  prefixSize 
)

Definition at line 2691 of file zstd_decompress.c.

2692 {
2693  return ZSTD_DCtx_refPrefix_advanced(dctx, prefix, prefixSize, ZSTD_dct_rawContent);
2694 }
size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx *dctx, const void *prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)

◆ ZSTD_DCtx_refPrefix_advanced()

size_t ZSTD_DCtx_refPrefix_advanced ( ZSTD_DCtx dctx,
const void prefix,
size_t  prefixSize,
ZSTD_dictContentType_e  dictContentType 
)

Definition at line 2686 of file zstd_decompress.c.

2687 {
2688  return ZSTD_DCtx_loadDictionary_advanced(dctx, prefix, prefixSize, ZSTD_dlm_byRef, dictContentType);
2689 }
size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx *dctx, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)

Referenced by ZSTD_DCtx_refPrefix().

◆ ZSTD_DCtx_reset()

void ZSTD_DCtx_reset ( ZSTD_DCtx dctx)

Definition at line 3103 of file zstd_decompress.c.

3104 {
3105  (void)ZSTD_initDStream(dctx);
3106  dctx->format = ZSTD_f_zstd1;
3108 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define ZSTD_MAXWINDOWSIZE_DEFAULT
ZSTD_format_e format
size_t ZSTD_initDStream(ZSTD_DStream *zds)
size_t maxWindowSize

◆ ZSTD_DCtx_setFormat()

size_t ZSTD_DCtx_setFormat ( ZSTD_DCtx dctx,
ZSTD_format_e  format 
)

Definition at line 2768 of file zstd_decompress.c.

2769 {
2770  DEBUGLOG(4, "ZSTD_DCtx_setFormat : %u", (unsigned)format);
2771  if (dctx->streamStage != zdss_init) return ERROR(stage_wrong);
2772  dctx->format = format;
2773  return 0;
2774 }
#define ERROR(name)
Definition: error_private.h:53
ZSTD_dStreamStage streamStage
ZSTD_format_e format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define DEBUGLOG(l,...)
Definition: debug.h:115

◆ ZSTD_DCtx_setMaxWindowSize()

size_t ZSTD_DCtx_setMaxWindowSize ( ZSTD_DCtx dctx,
size_t  maxWindowSize 
)

Definition at line 2761 of file zstd_decompress.c.

2762 {
2763  if (dctx->streamStage != zdss_init) return ERROR(stage_wrong);
2764  dctx->maxWindowSize = maxWindowSize;
2765  return 0;
2766 }
#define ERROR(name)
Definition: error_private.h:53
ZSTD_dStreamStage streamStage
size_t maxWindowSize

◆ ZSTD_DDictDictContent()

static const void * ZSTD_DDictDictContent ( const ZSTD_DDict ddict)
static

Definition at line 2377 of file zstd_decompress.c.

2378 {
2379  assert(ddict != NULL);
2380  return ddict->dictContent;
2381 }
const void * dictContent
#define assert(x)
Definition: debug.h:53
smooth NULL
Definition: ftsmooth.c:416

Referenced by ZSTD_decompressMultiFrame().

◆ ZSTD_DDictDictSize()

static size_t ZSTD_DDictDictSize ( const ZSTD_DDict ddict)
static

Definition at line 2383 of file zstd_decompress.c.

2384 {
2385  assert(ddict != NULL);
2386  return ddict->dictSize;
2387 }
#define assert(x)
Definition: debug.h:53
smooth NULL
Definition: ftsmooth.c:416

Referenced by ZSTD_decompressMultiFrame().

◆ ZSTD_decodeFrameHeader()

static size_t ZSTD_decodeFrameHeader ( ZSTD_DCtx dctx,
const void src,
size_t  headerSize 
)
static

ZSTD_decodeFrameHeader() : headerSize must be the size provided by ZSTD_frameHeaderSize().

Returns
: 0 if success, or an error code, which can be tested using ZSTD_isError()

Definition at line 517 of file zstd_decompress.c.

518 {
519  size_t const result = ZSTD_getFrameHeader_advanced(&(dctx->fParams), src, headerSize, dctx->format);
520  if (ZSTD_isError(result)) return result; /* invalid header */
521  if (result>0) return ERROR(srcSize_wrong); /* headerSize too small */
522  if (dctx->fParams.dictID && (dctx->dictID != dctx->fParams.dictID))
523  return ERROR(dictionary_wrong);
524  if (dctx->fParams.checksumFlag) XXH64_reset(&dctx->xxhState, 0);
525  return 0;
526 }
ZSTD_frameHeader fParams
#define ERROR(name)
Definition: error_private.h:53
XXH64_state_t xxhState
ZSTD_format_e format
size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader *zfhPtr, const void *src, size_t srcSize, ZSTD_format_e format)
GLenum src
Definition: glext.h:6340
#define ZSTD_isError
XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t *statePtr, unsigned long long seed)
Definition: xxhash.c:592
GLuint64EXT * result
Definition: glext.h:11304

Referenced by ZSTD_decompressContinue(), ZSTD_decompressFrame(), and ZSTD_decompressStream().

◆ ZSTD_decodeLiteralsBlock()

size_t ZSTD_decodeLiteralsBlock ( ZSTD_DCtx dctx,
const void src,
size_t  srcSize 
)

ZSTD_decodeLiteralsBlock() :

Returns
: nb of bytes read from src (< srcSize ) note : symbol not declared but exposed for fullbench

Definition at line 577 of file zstd_decompress.c.

579 {
580  if (srcSize < MIN_CBLOCK_SIZE) return ERROR(corruption_detected);
581 
582  { const BYTE* const istart = (const BYTE*) src;
583  symbolEncodingType_e const litEncType = (symbolEncodingType_e)(istart[0] & 3);
584 
585  switch(litEncType)
586  {
587  case set_repeat:
588  if (dctx->litEntropy==0) return ERROR(dictionary_corrupted);
589  /* fall-through */
590 
591  case set_compressed:
592  if (srcSize < 5) return ERROR(corruption_detected); /* srcSize >= MIN_CBLOCK_SIZE == 3; here we need up to 5 for case 3 */
593  { size_t lhSize, litSize, litCSize;
594  U32 singleStream=0;
595  U32 const lhlCode = (istart[0] >> 2) & 3;
596  U32 const lhc = MEM_readLE32(istart);
597  switch(lhlCode)
598  {
599  case 0: case 1: default: /* note : default is impossible, since lhlCode into [0..3] */
600  /* 2 - 2 - 10 - 10 */
601  singleStream = !lhlCode;
602  lhSize = 3;
603  litSize = (lhc >> 4) & 0x3FF;
604  litCSize = (lhc >> 14) & 0x3FF;
605  break;
606  case 2:
607  /* 2 - 2 - 14 - 14 */
608  lhSize = 4;
609  litSize = (lhc >> 4) & 0x3FFF;
610  litCSize = lhc >> 18;
611  break;
612  case 3:
613  /* 2 - 2 - 18 - 18 */
614  lhSize = 5;
615  litSize = (lhc >> 4) & 0x3FFFF;
616  litCSize = (lhc >> 22) + (istart[4] << 10);
617  break;
618  }
619  if (litSize > ZSTD_BLOCKSIZE_MAX) return ERROR(corruption_detected);
620  if (litCSize + lhSize > srcSize) return ERROR(corruption_detected);
621 
622  /* prefetch huffman table if cold */
623  if (dctx->ddictIsCold && (litSize > 768 /* heuristic */)) {
624  PREFETCH_AREA(dctx->HUFptr, sizeof(dctx->entropy.hufTable));
625  }
626 
627  if (HUF_isError((litEncType==set_repeat) ?
628  ( singleStream ?
629  HUF_decompress1X_usingDTable_bmi2(dctx->litBuffer, litSize, istart+lhSize, litCSize, dctx->HUFptr, dctx->bmi2) :
630  HUF_decompress4X_usingDTable_bmi2(dctx->litBuffer, litSize, istart+lhSize, litCSize, dctx->HUFptr, dctx->bmi2) ) :
631  ( singleStream ?
632  HUF_decompress1X1_DCtx_wksp_bmi2(dctx->entropy.hufTable, dctx->litBuffer, litSize, istart+lhSize, litCSize,
633  dctx->workspace, sizeof(dctx->workspace), dctx->bmi2) :
634  HUF_decompress4X_hufOnly_wksp_bmi2(dctx->entropy.hufTable, dctx->litBuffer, litSize, istart+lhSize, litCSize,
635  dctx->workspace, sizeof(dctx->workspace), dctx->bmi2))))
636  return ERROR(corruption_detected);
637 
638  dctx->litPtr = dctx->litBuffer;
639  dctx->litSize = litSize;
640  dctx->litEntropy = 1;
641  if (litEncType==set_compressed) dctx->HUFptr = dctx->entropy.hufTable;
642  memset(dctx->litBuffer + dctx->litSize, 0, WILDCOPY_OVERLENGTH);
643  return litCSize + lhSize;
644  }
645 
646  case set_basic:
647  { size_t litSize, lhSize;
648  U32 const lhlCode = ((istart[0]) >> 2) & 3;
649  switch(lhlCode)
650  {
651  case 0: case 2: default: /* note : default is impossible, since lhlCode into [0..3] */
652  lhSize = 1;
653  litSize = istart[0] >> 3;
654  break;
655  case 1:
656  lhSize = 2;
657  litSize = MEM_readLE16(istart) >> 4;
658  break;
659  case 3:
660  lhSize = 3;
661  litSize = MEM_readLE24(istart) >> 4;
662  break;
663  }
664 
665  if (lhSize+litSize+WILDCOPY_OVERLENGTH > srcSize) { /* risk reading beyond src buffer with wildcopy */
666  if (litSize+lhSize > srcSize) return ERROR(corruption_detected);
667  memcpy(dctx->litBuffer, istart+lhSize, litSize);
668  dctx->litPtr = dctx->litBuffer;
669  dctx->litSize = litSize;
670  memset(dctx->litBuffer + dctx->litSize, 0, WILDCOPY_OVERLENGTH);
671  return lhSize+litSize;
672  }
673  /* direct reference into compressed stream */
674  dctx->litPtr = istart+lhSize;
675  dctx->litSize = litSize;
676  return lhSize+litSize;
677  }
678 
679  case set_rle:
680  { U32 const lhlCode = ((istart[0]) >> 2) & 3;
681  size_t litSize, lhSize;
682  switch(lhlCode)
683  {
684  case 0: case 2: default: /* note : default is impossible, since lhlCode into [0..3] */
685  lhSize = 1;
686  litSize = istart[0] >> 3;
687  break;
688  case 1:
689  lhSize = 2;
690  litSize = MEM_readLE16(istart) >> 4;
691  break;
692  case 3:
693  lhSize = 3;
694  litSize = MEM_readLE24(istart) >> 4;
695  if (srcSize<4) return ERROR(corruption_detected); /* srcSize >= MIN_CBLOCK_SIZE == 3; here we need lhSize+1 = 4 */
696  break;
697  }
698  if (litSize > ZSTD_BLOCKSIZE_MAX) return ERROR(corruption_detected);
699  memset(dctx->litBuffer, istart[lhSize], litSize + WILDCOPY_OVERLENGTH);
700  dctx->litPtr = dctx->litBuffer;
701  dctx->litSize = litSize;
702  return lhSize+1;
703  }
704  default:
705  return ERROR(corruption_detected); /* impossible */
706  }
707  }
708 }
#define WILDCOPY_OVERLENGTH
symbolEncodingType_e
Definition: zstd_internal.h:92
#define ERROR(name)
Definition: error_private.h:53
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
Definition: mem.h:273
BYTE litBuffer[ZSTD_BLOCKSIZE_MAX+WILDCOPY_OVERLENGTH]
unsigned int U32
Definition: mem.h:77
size_t HUF_decompress4X_usingDTable_bmi2(void *dst, size_t maxDstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable, int bmi2)
U32 workspace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32]
#define PREFETCH_AREA(p, s)
Definition: compiler.h:114
MEM_STATIC U16 MEM_readLE16(const void *memPtr)
Definition: mem.h:241
#define HUF_isError
size_t HUF_decompress4X_hufOnly_wksp_bmi2(HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize, int bmi2)
size_t HUF_decompress1X1_DCtx_wksp_bmi2(HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize, int bmi2)
ZSTD_entropyDTables_t entropy
HUF_DTable hufTable[HUF_DTABLE_SIZE(HufLog)]
#define MIN_CBLOCK_SIZE
Definition: zstd_internal.h:89
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
GLenum src
Definition: glext.h:6340
const BYTE * litPtr
size_t HUF_decompress1X_usingDTable_bmi2(void *dst, size_t maxDstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable, int bmi2)
const HUF_DTable * HUFptr
#define memset(x, y, z)
Definition: compat.h:39
MEM_STATIC U32 MEM_readLE24(const void *memPtr)
Definition: mem.h:262

Referenced by ZSTD_decompressBlock_internal().

◆ ZSTD_decodeSeqHeaders()

size_t ZSTD_decodeSeqHeaders ( ZSTD_DCtx dctx,
int nbSeqPtr,
const void src,
size_t  srcSize 
)

Definition at line 982 of file zstd_decompress.c.

984 {
985  const BYTE* const istart = (const BYTE* const)src;
986  const BYTE* const iend = istart + srcSize;
987  const BYTE* ip = istart;
988  int nbSeq;
989  DEBUGLOG(5, "ZSTD_decodeSeqHeaders");
990 
991  /* check */
992  if (srcSize < MIN_SEQUENCES_SIZE) return ERROR(srcSize_wrong);
993 
994  /* SeqHead */
995  nbSeq = *ip++;
996  if (!nbSeq) { *nbSeqPtr=0; return 1; }
997  if (nbSeq > 0x7F) {
998  if (nbSeq == 0xFF) {
999  if (ip+2 > iend) return ERROR(srcSize_wrong);
1000  nbSeq = MEM_readLE16(ip) + LONGNBSEQ, ip+=2;
1001  } else {
1002  if (ip >= iend) return ERROR(srcSize_wrong);
1003  nbSeq = ((nbSeq-0x80)<<8) + *ip++;
1004  }
1005  }
1006  *nbSeqPtr = nbSeq;
1007 
1008  /* FSE table descriptors */
1009  if (ip+4 > iend) return ERROR(srcSize_wrong); /* minimum possible size */
1010  { symbolEncodingType_e const LLtype = (symbolEncodingType_e)(*ip >> 6);
1011  symbolEncodingType_e const OFtype = (symbolEncodingType_e)((*ip >> 4) & 3);
1012  symbolEncodingType_e const MLtype = (symbolEncodingType_e)((*ip >> 2) & 3);
1013  ip++;
1014 
1015  /* Build DTables */
1016  { size_t const llhSize = ZSTD_buildSeqTable(dctx->entropy.LLTable, &dctx->LLTptr,
1017  LLtype, MaxLL, LLFSELog,
1018  ip, iend-ip,
1019  LL_base, LL_bits,
1021  dctx->ddictIsCold, nbSeq);
1022  if (ZSTD_isError(llhSize)) return ERROR(corruption_detected);
1023  ip += llhSize;
1024  }
1025 
1026  { size_t const ofhSize = ZSTD_buildSeqTable(dctx->entropy.OFTable, &dctx->OFTptr,
1027  OFtype, MaxOff, OffFSELog,
1028  ip, iend-ip,
1029  OF_base, OF_bits,
1031  dctx->ddictIsCold, nbSeq);
1032  if (ZSTD_isError(ofhSize)) return ERROR(corruption_detected);
1033  ip += ofhSize;
1034  }
1035 
1036  { size_t const mlhSize = ZSTD_buildSeqTable(dctx->entropy.MLTable, &dctx->MLTptr,
1037  MLtype, MaxML, MLFSELog,
1038  ip, iend-ip,
1039  ML_base, ML_bits,
1041  dctx->ddictIsCold, nbSeq);
1042  if (ZSTD_isError(mlhSize)) return ERROR(corruption_detected);
1043  ip += mlhSize;
1044  }
1045  }
1046 
1047  /* prefetch dictionary content */
1048  if (dctx->ddictIsCold) {
1049  size_t const dictSize = (const char*)dctx->prefixStart - (const char*)dctx->virtualStart;
1050  size_t const psmin = MIN(dictSize, (size_t)(64*nbSeq) /* heuristic */ );
1051  size_t const pSize = MIN(psmin, 128 KB /* protection */ );
1052  const void* const pStart = (const char*)dctx->dictEnd - pSize;
1053  PREFETCH_AREA(pStart, pSize);
1054  dctx->ddictIsCold = 0;
1055  }
1056 
1057  return ip-istart;
1058 }
symbolEncodingType_e
Definition: zstd_internal.h:92
static const U32 OF_base[MaxOff+1]
static const U32 OF_bits[MaxOff+1]
#define ERROR(name)
Definition: error_private.h:53
static const U32 LL_bits[MaxLL+1]
const ZSTD_seqSymbol * OFTptr
static const ZSTD_seqSymbol OF_defaultDTable[(1<< OF_DEFAULTNORMLOG)+1]
static size_t ZSTD_buildSeqTable(ZSTD_seqSymbol *DTableSpace, const ZSTD_seqSymbol **DTablePtr, symbolEncodingType_e type, U32 max, U32 maxLog, const void *src, size_t srcSize, const U32 *baseValue, const U32 *nbAdditionalBits, const ZSTD_seqSymbol *defaultTable, U32 flagRepeatTable, int ddictIsCold, int nbSeq)
ZSTD_seqSymbol OFTable[SEQSYMBOL_TABLE_SIZE(OffFSELog)]
static const U32 ML_base[MaxML+1]
const void * dictEnd
T MIN(T a, T b)
Definition: polytest.cpp:79
#define DEBUGLOG(l,...)
Definition: debug.h:115
const void * virtualStart
const void * prefixStart
#define MIN_SEQUENCES_SIZE
Definition: zstd_internal.h:88
#define MaxML
#define MLFSELog
#define PREFETCH_AREA(p, s)
Definition: compiler.h:114
const ZSTD_seqSymbol * LLTptr
const ZSTD_seqSymbol * MLTptr
MEM_STATIC U16 MEM_readLE16(const void *memPtr)
Definition: mem.h:241
Definition: dhcpd.h:61
ZSTD_entropyDTables_t entropy
ZSTD_seqSymbol MLTable[SEQSYMBOL_TABLE_SIZE(MLFSELog)]
#define OffFSELog
unsigned char BYTE
Definition: mem.h:68
#define LONGNBSEQ
Definition: zstd_internal.h:94
GLenum src
Definition: glext.h:6340
#define MaxOff
#define ZSTD_isError
static const ZSTD_seqSymbol LL_defaultDTable[(1<< LL_DEFAULTNORMLOG)+1]
ZSTD_seqSymbol LLTable[SEQSYMBOL_TABLE_SIZE(LLFSELog)]
static const U32 ML_bits[MaxML+1]
#define MaxLL
#define LLFSELog
#define KB
Definition: setuplib.h:52
static const U32 LL_base[MaxLL+1]
static const ZSTD_seqSymbol ML_defaultDTable[(1<< ML_DEFAULTNORMLOG)+1]

Referenced by ZSTD_decompressBlock_internal().

◆ ZSTD_decodeSequence()

FORCE_INLINE_TEMPLATE seq_t ZSTD_decodeSequence ( seqState_t seqState,
const ZSTD_longOffset_e  longOffsets 
)

Definition at line 1326 of file zstd_decompress.c.

1327 {
1328  seq_t seq;
1329  U32 const llBits = seqState->stateLL.table[seqState->stateLL.state].nbAdditionalBits;
1330  U32 const mlBits = seqState->stateML.table[seqState->stateML.state].nbAdditionalBits;
1331  U32 const ofBits = seqState->stateOffb.table[seqState->stateOffb.state].nbAdditionalBits;
1332  U32 const totalBits = llBits+mlBits+ofBits;
1333  U32 const llBase = seqState->stateLL.table[seqState->stateLL.state].baseValue;
1334  U32 const mlBase = seqState->stateML.table[seqState->stateML.state].baseValue;
1335  U32 const ofBase = seqState->stateOffb.table[seqState->stateOffb.state].baseValue;
1336 
1337  /* sequence */
1338  { size_t offset;
1339  if (!ofBits)
1340  offset = 0;
1341  else {
1344  assert(ofBits <= MaxOff);
1345  if (MEM_32bits() && longOffsets && (ofBits >= STREAM_ACCUMULATOR_MIN_32)) {
1346  U32 const extraBits = ofBits - MIN(ofBits, 32 - seqState->DStream.bitsConsumed);
1347  offset = ofBase + (BIT_readBitsFast(&seqState->DStream, ofBits - extraBits) << extraBits);
1348  BIT_reloadDStream(&seqState->DStream);
1349  if (extraBits) offset += BIT_readBitsFast(&seqState->DStream, extraBits);
1350  assert(extraBits <= LONG_OFFSETS_MAX_EXTRA_BITS_32); /* to avoid another reload */
1351  } else {
1352  offset = ofBase + BIT_readBitsFast(&seqState->DStream, ofBits/*>0*/); /* <= (ZSTD_WINDOWLOG_MAX-1) bits */
1353  if (MEM_32bits()) BIT_reloadDStream(&seqState->DStream);
1354  }
1355  }
1356 
1357  if (ofBits <= 1) {
1358  offset += (llBase==0);
1359  if (offset) {
1360  size_t temp = (offset==3) ? seqState->prevOffset[0] - 1 : seqState->prevOffset[offset];
1361  temp += !temp; /* 0 is not valid; input is corrupted; force offset to 1 */
1362  if (offset != 1) seqState->prevOffset[2] = seqState->prevOffset[1];
1363  seqState->prevOffset[1] = seqState->prevOffset[0];
1364  seqState->prevOffset[0] = offset = temp;
1365  } else { /* offset == 0 */
1366  offset = seqState->prevOffset[0];
1367  }
1368  } else {
1369  seqState->prevOffset[2] = seqState->prevOffset[1];
1370  seqState->prevOffset[1] = seqState->prevOffset[0];
1371  seqState->prevOffset[0] = offset;
1372  }
1373  seq.offset = offset;
1374  }
1375 
1376  seq.matchLength = mlBase
1377  + ((mlBits>0) ? BIT_readBitsFast(&seqState->DStream, mlBits/*>0*/) : 0); /* <= 16 bits */
1379  BIT_reloadDStream(&seqState->DStream);
1381  BIT_reloadDStream(&seqState->DStream);
1382  /* Ensure there are enough bits to read the rest of data in 64-bit mode. */
1384 
1385  seq.litLength = llBase
1386  + ((llBits>0) ? BIT_readBitsFast(&seqState->DStream, llBits/*>0*/) : 0); /* <= 16 bits */
1387  if (MEM_32bits())
1388  BIT_reloadDStream(&seqState->DStream);
1389 
1390  DEBUGLOG(6, "seq: litL=%u, matchL=%u, offset=%u",
1391  (U32)seq.litLength, (U32)seq.matchLength, (U32)seq.offset);
1392 
1393  /* ANS state update */
1394  ZSTD_updateFseState(&seqState->stateLL, &seqState->DStream); /* <= 9 bits */
1395  ZSTD_updateFseState(&seqState->stateML, &seqState->DStream); /* <= 9 bits */
1396  if (MEM_32bits()) BIT_reloadDStream(&seqState->DStream); /* <= 18 bits */
1397  ZSTD_updateFseState(&seqState->stateOffb, &seqState->DStream); /* <= 8 bits */
1398 
1399  return seq;
1400 }
BIT_DStream_t DStream
GLintptr offset
Definition: glext.h:5920
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
MEM_STATIC unsigned MEM_32bits(void)
Definition: mem.h:110
#define LONG_OFFSETS_MAX_EXTRA_BITS_32
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t *bitD)
Definition: bitstream.h:414
ZSTD_fseState stateOffb
MEM_STATIC unsigned MEM_64bits(void)
Definition: mem.h:111
ZSTD_fseState stateML
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t *bitD, unsigned nbBits)
T MIN(T a, T b)
Definition: polytest.cpp:79
#define ZSTD_STATIC_ASSERT(c)
Definition: zstd_internal.h:43
size_t litLength
#define DEBUGLOG(l,...)
Definition: debug.h:115
const ZSTD_seqSymbol * table
#define MLFSELog
FORCE_INLINE_TEMPLATE void ZSTD_updateFseState(ZSTD_fseState *DStatePtr, BIT_DStream_t *bitD)
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define OffFSELog
#define STREAM_ACCUMULATOR_MIN_32
Definition: bitstream.h:62
#define STREAM_ACCUMULATOR_MIN_64
Definition: bitstream.h:63
unsigned bitsConsumed
Definition: bitstream.h:110
ZSTD_fseState stateLL
size_t matchLength
#define MaxOff
static calc_node_t temp
Definition: rpn_ieee.c:38
size_t prevOffset[ZSTD_REP_NUM]
#define LLFSELog
size_t offset

Referenced by ZSTD_decompressSequences_body().

◆ ZSTD_decodeSequenceLong()

FORCE_INLINE_TEMPLATE seq_t ZSTD_decodeSequenceLong ( seqState_t seqState,
ZSTD_longOffset_e const  longOffsets 
)

Definition at line 1468 of file zstd_decompress.c.

1469 {
1470  seq_t seq;
1471  U32 const llBits = seqState->stateLL.table[seqState->stateLL.state].nbAdditionalBits;
1472  U32 const mlBits = seqState->stateML.table[seqState->stateML.state].nbAdditionalBits;
1473  U32 const ofBits = seqState->stateOffb.table[seqState->stateOffb.state].nbAdditionalBits;
1474  U32 const totalBits = llBits+mlBits+ofBits;
1475  U32 const llBase = seqState->stateLL.table[seqState->stateLL.state].baseValue;
1476  U32 const mlBase = seqState->stateML.table[seqState->stateML.state].baseValue;
1477  U32 const ofBase = seqState->stateOffb.table[seqState->stateOffb.state].baseValue;
1478 
1479  /* sequence */
1480  { size_t offset;
1481  if (!ofBits)
1482  offset = 0;
1483  else {
1486  assert(ofBits <= MaxOff);
1487  if (MEM_32bits() && longOffsets) {
1488  U32 const extraBits = ofBits - MIN(ofBits, STREAM_ACCUMULATOR_MIN_32-1);
1489  offset = ofBase + (BIT_readBitsFast(&seqState->DStream, ofBits - extraBits) << extraBits);
1490  if (MEM_32bits() || extraBits) BIT_reloadDStream(&seqState->DStream);
1491  if (extraBits) offset += BIT_readBitsFast(&seqState->DStream, extraBits);
1492  } else {
1493  offset = ofBase + BIT_readBitsFast(&seqState->DStream, ofBits); /* <= (ZSTD_WINDOWLOG_MAX-1) bits */
1494  if (MEM_32bits()) BIT_reloadDStream(&seqState->DStream);
1495  }
1496  }
1497 
1498  if (ofBits <= 1) {
1499  offset += (llBase==0);
1500  if (offset) {
1501  size_t temp = (offset==3) ? seqState->prevOffset[0] - 1 : seqState->prevOffset[offset];
1502  temp += !temp; /* 0 is not valid; input is corrupted; force offset to 1 */
1503  if (offset != 1) seqState->prevOffset[2] = seqState->prevOffset[1];
1504  seqState->prevOffset[1] = seqState->prevOffset[0];
1505  seqState->prevOffset[0] = offset = temp;
1506  } else {
1507  offset = seqState->prevOffset[0];
1508  }
1509  } else {
1510  seqState->prevOffset[2] = seqState->prevOffset[1];
1511  seqState->prevOffset[1] = seqState->prevOffset[0];
1512  seqState->prevOffset[0] = offset;
1513  }
1514  seq.offset = offset;
1515  }
1516 
1517  seq.matchLength = mlBase + ((mlBits>0) ? BIT_readBitsFast(&seqState->DStream, mlBits) : 0); /* <= 16 bits */
1519  BIT_reloadDStream(&seqState->DStream);
1521  BIT_reloadDStream(&seqState->DStream);
1522  /* Verify that there is enough bits to read the rest of the data in 64-bit mode. */
1524 
1525  seq.litLength = llBase + ((llBits>0) ? BIT_readBitsFast(&seqState->DStream, llBits) : 0); /* <= 16 bits */
1526  if (MEM_32bits())
1527  BIT_reloadDStream(&seqState->DStream);
1528 
1529  { size_t const pos = seqState->pos + seq.litLength;
1530  const BYTE* const matchBase = (seq.offset > pos) ? seqState->dictEnd : seqState->prefixStart;
1531  seq.match = matchBase + pos - seq.offset; /* note : this operation can overflow when seq.offset is really too large, which can only happen when input is corrupted.
1532  * No consequence though : no memory access will occur, overly large offset will be detected in ZSTD_execSequenceLong() */
1533  seqState->pos = pos + seq.matchLength;
1534  }
1535 
1536  /* ANS state update */
1537  ZSTD_updateFseState(&seqState->stateLL, &seqState->DStream); /* <= 9 bits */
1538  ZSTD_updateFseState(&seqState->stateML, &seqState->DStream); /* <= 9 bits */
1539  if (MEM_32bits()) BIT_reloadDStream(&seqState->DStream); /* <= 18 bits */
1540  ZSTD_updateFseState(&seqState->stateOffb, &seqState->DStream); /* <= 8 bits */
1541 
1542  return seq;
1543 }
const BYTE * dictEnd
BIT_DStream_t DStream
GLintptr offset
Definition: glext.h:5920
const BYTE * prefixStart
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
MEM_STATIC unsigned MEM_32bits(void)
Definition: mem.h:110
#define LONG_OFFSETS_MAX_EXTRA_BITS_32
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t *bitD)
Definition: bitstream.h:414
ZSTD_fseState stateOffb
MEM_STATIC unsigned MEM_64bits(void)
Definition: mem.h:111
ZSTD_fseState stateML
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t *bitD, unsigned nbBits)
T MIN(T a, T b)
Definition: polytest.cpp:79
#define ZSTD_STATIC_ASSERT(c)
Definition: zstd_internal.h:43
size_t litLength
const ZSTD_seqSymbol * table
#define MLFSELog
FORCE_INLINE_TEMPLATE void ZSTD_updateFseState(ZSTD_fseState *DStatePtr, BIT_DStream_t *bitD)
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define OffFSELog
const BYTE * match
#define STREAM_ACCUMULATOR_MIN_32
Definition: bitstream.h:62
#define STREAM_ACCUMULATOR_MIN_64
Definition: bitstream.h:63
ZSTD_fseState stateLL
size_t matchLength
unsigned char BYTE
Definition: mem.h:68
#define MaxOff
static calc_node_t temp
Definition: rpn_ieee.c:38
size_t prevOffset[ZSTD_REP_NUM]
#define LLFSELog
size_t offset

Referenced by ZSTD_decompressSequencesLong_body().

◆ ZSTD_decodingBufferSize_min()

size_t ZSTD_decodingBufferSize_min ( unsigned long long  windowSize,
unsigned long long  frameContentSize 
)

Definition at line 2782 of file zstd_decompress.c.

2783 {
2784  size_t const blockSize = (size_t) MIN(windowSize, ZSTD_BLOCKSIZE_MAX);
2785  unsigned long long const neededRBSize = windowSize + blockSize + (WILDCOPY_OVERLENGTH * 2);
2786  unsigned long long const neededSize = MIN(frameContentSize, neededRBSize);
2787  size_t const minRBSize = (size_t) neededSize;
2788  if ((unsigned long long)minRBSize != neededSize) return ERROR(frameParameter_windowTooLarge);
2789  return minRBSize;
2790 }
#define WILDCOPY_OVERLENGTH
#define ERROR(name)
Definition: error_private.h:53
T MIN(T a, T b)
Definition: polytest.cpp:79
__kernel_size_t size_t
Definition: linux.h:237

Referenced by ZSTD_decompressStream(), and ZSTD_estimateDStreamSize().

◆ ZSTD_decompress()

size_t ZSTD_decompress ( void dst,
size_t  dstCapacity,
const void src,
size_t  compressedSize 
)

ZSTD_decompress() : compressedSize : must be the exact size of some number of compressed and/or skippable frames. dstCapacity is an upper bound of originalSize to regenerate. If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data.

Returns
: the number of bytes decompressed into dst (<= dstCapacity), or an errorCode if it fails (which can be tested using ZSTD_isError()).

Definition at line 2040 of file zstd_decompress.c.

2041 {
2042 #if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE>=1)
2043  size_t regenSize;
2044  ZSTD_DCtx* const dctx = ZSTD_createDCtx();
2045  if (dctx==NULL) return ERROR(memory_allocation);
2046  regenSize = ZSTD_decompressDCtx(dctx, dst, dstCapacity, src, srcSize);
2047  ZSTD_freeDCtx(dctx);
2048  return regenSize;
2049 #else /* stack mode */
2050  ZSTD_DCtx dctx;
2051  ZSTD_initDCtx_internal(&dctx);
2052  return ZSTD_decompressDCtx(&dctx, dst, dstCapacity, src, srcSize);
2053 #endif
2054 }
ZSTD_DCtx * ZSTD_createDCtx(void)
#define ERROR(name)
Definition: error_private.h:53
size_t ZSTD_decompressDCtx(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
smooth NULL
Definition: ftsmooth.c:416
size_t ZSTD_freeDCtx(ZSTD_DCtx *dctx)
GLenum src
Definition: glext.h:6340
static void ZSTD_initDCtx_internal(ZSTD_DCtx *dctx)
GLenum GLenum dst
Definition: glext.h:6340

◆ ZSTD_decompress_generic()

size_t ZSTD_decompress_generic ( ZSTD_DCtx dctx,
ZSTD_outBuffer output,
ZSTD_inBuffer input 
)

Definition at line 3084 of file zstd_decompress.c.

3085 {
3086  return ZSTD_decompressStream(dctx, output, input);
3087 }
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
GLenum GLenum GLenum input
Definition: glext.h:9031

Referenced by ZSTD_decompress_generic_simpleArgs().

◆ ZSTD_decompress_generic_simpleArgs()

size_t ZSTD_decompress_generic_simpleArgs ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
size_t dstPos,
const void src,
size_t  srcSize,
size_t srcPos 
)

Definition at line 3089 of file zstd_decompress.c.

3093 {
3094  ZSTD_outBuffer output = { dst, dstCapacity, *dstPos };
3095  ZSTD_inBuffer input = { src, srcSize, *srcPos };
3096  /* ZSTD_compress_generic() will check validity of dstPos and srcPos */
3097  size_t const cErr = ZSTD_decompress_generic(dctx, &output, &input);
3098  *dstPos = output.pos;
3099  *srcPos = input.pos;
3100  return cErr;
3101 }
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
size_t ZSTD_decompress_generic(ZSTD_DCtx *dctx, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
GLenum src
Definition: glext.h:6340
GLenum GLenum GLenum input
Definition: glext.h:9031
GLenum GLenum dst
Definition: glext.h:6340

◆ ZSTD_decompress_insertDictionary()

static size_t ZSTD_decompress_insertDictionary ( ZSTD_DCtx dctx,
const void dict,
size_t  dictSize 
)
static

Definition at line 2313 of file zstd_decompress.c.

2314 {
2315  if (dictSize < 8) return ZSTD_refDictContent(dctx, dict, dictSize);
2316  { U32 const magic = MEM_readLE32(dict);
2317  if (magic != ZSTD_MAGIC_DICTIONARY) {
2318  return ZSTD_refDictContent(dctx, dict, dictSize); /* pure content mode */
2319  } }
2320  dctx->dictID = MEM_readLE32((const char*)dict + ZSTD_FRAMEIDSIZE);
2321 
2322  /* load entropy tables */
2323  { size_t const eSize = ZSTD_loadEntropy(&dctx->entropy, dict, dictSize);
2324  if (ZSTD_isError(eSize)) return ERROR(dictionary_corrupted);
2325  dict = (const char*)dict + eSize;
2326  dictSize -= eSize;
2327  }
2328  dctx->litEntropy = dctx->fseEntropy = 1;
2329 
2330  /* reference dictionary content */
2331  return ZSTD_refDictContent(dctx, dict, dictSize);
2332 }
#define ERROR(name)
Definition: error_private.h:53
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
Definition: mem.h:273
unsigned int U32
Definition: mem.h:77
u32_t magic(void)
static size_t ZSTD_refDictContent(ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
ZSTD_entropyDTables_t entropy
#define ZSTD_isError
#define ZSTD_FRAMEIDSIZE
Definition: zstd_internal.h:82
static size_t ZSTD_loadEntropy(ZSTD_entropyDTables_t *entropy, const void *const dict, size_t const dictSize)

Referenced by ZSTD_decompressBegin_usingDict().

◆ ZSTD_decompress_usingDDict()

size_t ZSTD_decompress_usingDDict ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const ZSTD_DDict ddict 
)

ZSTD_decompress_usingDDict() : Decompression using a pre-digested Dictionary Use dictionary without significant overhead.

Definition at line 2616 of file zstd_decompress.c.

2620 {
2621  /* pass content and size in case legacy frames are encountered */
2622  return ZSTD_decompressMultiFrame(dctx, dst, dstCapacity, src, srcSize,
2623  NULL, 0,
2624  ddict);
2625 }
static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, const ZSTD_DDict *ddict)
smooth NULL
Definition: ftsmooth.c:416
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_decompressStream().

◆ ZSTD_decompress_usingDict()

size_t ZSTD_decompress_usingDict ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const void dict,
size_t  dictSize 
)

ZSTD_decompress_usingDict() : Decompression using a predefined Dictionary (see dictBuilder/zdict.h). Dictionary must be identical to the one used during compression. Note : This function loads the dictionary, resulting in significant startup delay. Note : When dict == NULL || dictSize < 8 no dictionary is used.

Definition at line 2025 of file zstd_decompress.c.

2029 {
2030  return ZSTD_decompressMultiFrame(dctx, dst, dstCapacity, src, srcSize, dict, dictSize, NULL);
2031 }
static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, const ZSTD_DDict *ddict)
smooth NULL
Definition: ftsmooth.c:416
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_decompressDCtx().

◆ ZSTD_decompressBegin()

size_t ZSTD_decompressBegin ( ZSTD_DCtx dctx)

Definition at line 2334 of file zstd_decompress.c.

2335 {
2336  assert(dctx != NULL);
2337  dctx->expected = ZSTD_startingInputLength(dctx->format); /* dctx->format must be properly set */
2339  dctx->decodedSize = 0;
2340  dctx->previousDstEnd = NULL;
2341  dctx->prefixStart = NULL;
2342  dctx->virtualStart = NULL;
2343  dctx->dictEnd = NULL;
2344  dctx->entropy.hufTable[0] = (HUF_DTable)((HufLog)*0x1000001); /* cover both little and big endian */
2345  dctx->litEntropy = dctx->fseEntropy = 0;
2346  dctx->dictID = 0;
2347  ZSTD_STATIC_ASSERT(sizeof(dctx->entropy.rep) == sizeof(repStartValue));
2348  memcpy(dctx->entropy.rep, repStartValue, sizeof(repStartValue)); /* initial repcodes */
2349  dctx->LLTptr = dctx->entropy.LLTable;
2350  dctx->MLTptr = dctx->entropy.MLTable;
2351  dctx->OFTptr = dctx->entropy.OFTable;
2352  dctx->HUFptr = dctx->entropy.hufTable;
2353  return 0;
2354 }
const void * previousDstEnd
static size_t ZSTD_startingInputLength(ZSTD_format_e format)
U32 rep[ZSTD_REP_NUM]
const ZSTD_seqSymbol * OFTptr
#define assert(x)
Definition: debug.h:53
ZSTD_seqSymbol OFTable[SEQSYMBOL_TABLE_SIZE(OffFSELog)]
const void * dictEnd
ZSTD_format_e format
#define ZSTD_STATIC_ASSERT(c)
Definition: zstd_internal.h:43
const void * virtualStart
const void * prefixStart
#define HufLog
Definition: zstd_internal.h:91
smooth NULL
Definition: ftsmooth.c:416
static const U32 repStartValue[ZSTD_REP_NUM]
Definition: zstd_internal.h:64
const ZSTD_seqSymbol * LLTptr
const ZSTD_seqSymbol * MLTptr
ZSTD_entropyDTables_t entropy
ZSTD_seqSymbol MLTable[SEQSYMBOL_TABLE_SIZE(MLFSELog)]
ZSTD_dStage stage
HUF_DTable hufTable[HUF_DTABLE_SIZE(HufLog)]
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
ZSTD_seqSymbol LLTable[SEQSYMBOL_TABLE_SIZE(LLFSELog)]
const HUF_DTable * HUFptr

Referenced by ZSTD_decompressBegin_usingDDict(), and ZSTD_decompressBegin_usingDict().

◆ ZSTD_decompressBegin_usingDDict()

size_t ZSTD_decompressBegin_usingDDict ( ZSTD_DCtx dctx,
const ZSTD_DDict ddict 
)

Definition at line 2389 of file zstd_decompress.c.

2390 {
2391  DEBUGLOG(4, "ZSTD_decompressBegin_usingDDict");
2392  assert(dctx != NULL);
2393  if (ddict) {
2394  dctx->ddictIsCold = (dctx->dictEnd != (const char*)ddict->dictContent + ddict->dictSize);
2395  DEBUGLOG(4, "DDict is %s",
2396  dctx->ddictIsCold ? "~cold~" : "hot!");
2397  }
2398  CHECK_F( ZSTD_decompressBegin(dctx) );
2399  if (ddict) { /* NULL ddict is equivalent to no dictionary */
2400  dctx->dictID = ddict->dictID;
2401  dctx->prefixStart = ddict->dictContent;
2402  dctx->virtualStart = ddict->dictContent;
2403  dctx->dictEnd = (const BYTE*)ddict->dictContent + ddict->dictSize;
2404  dctx->previousDstEnd = dctx->dictEnd;
2405  if (ddict->entropyPresent) {
2406  dctx->litEntropy = 1;
2407  dctx->fseEntropy = 1;
2408  dctx->LLTptr = ddict->entropy.LLTable;
2409  dctx->MLTptr = ddict->entropy.MLTable;
2410  dctx->OFTptr = ddict->entropy.OFTable;
2411  dctx->HUFptr = ddict->entropy.hufTable;
2412  dctx->entropy.rep[0] = ddict->entropy.rep[0];
2413  dctx->entropy.rep[1] = ddict->entropy.rep[1];
2414  dctx->entropy.rep[2] = ddict->entropy.rep[2];
2415  } else {
2416  dctx->litEntropy = 0;
2417  dctx->fseEntropy = 0;
2418  }
2419  }
2420  return 0;
2421 }
const void * previousDstEnd
const void * dictContent
U32 rep[ZSTD_REP_NUM]
ZSTD_entropyDTables_t entropy
const ZSTD_seqSymbol * OFTptr
size_t ZSTD_decompressBegin(ZSTD_DCtx *dctx)
#define assert(x)
Definition: debug.h:53
ZSTD_seqSymbol OFTable[SEQSYMBOL_TABLE_SIZE(OffFSELog)]
const void * dictEnd
#define DEBUGLOG(l,...)
Definition: debug.h:115
const void * virtualStart
const void * prefixStart
smooth NULL
Definition: ftsmooth.c:416
#define CHECK_F(f)
Definition: fse_compress.c:661
const ZSTD_seqSymbol * LLTptr
const ZSTD_seqSymbol * MLTptr
if(!(yy_init))
Definition: macro.lex.yy.c:714
ZSTD_entropyDTables_t entropy
ZSTD_seqSymbol MLTable[SEQSYMBOL_TABLE_SIZE(MLFSELog)]
HUF_DTable hufTable[HUF_DTABLE_SIZE(HufLog)]
unsigned char BYTE
Definition: mem.h:68
ZSTD_seqSymbol LLTable[SEQSYMBOL_TABLE_SIZE(LLFSELog)]
const HUF_DTable * HUFptr

Referenced by ZSTD_decompressMultiFrame(), and ZSTD_decompressStream().

◆ ZSTD_decompressBegin_usingDict()

size_t ZSTD_decompressBegin_usingDict ( ZSTD_DCtx dctx,
const void dict,
size_t  dictSize 
)

Definition at line 2356 of file zstd_decompress.c.

2357 {
2358  CHECK_F( ZSTD_decompressBegin(dctx) );
2359  if (dict && dictSize)
2360  CHECK_E(ZSTD_decompress_insertDictionary(dctx, dict, dictSize), dictionary_corrupted);
2361  return 0;
2362 }
size_t ZSTD_decompressBegin(ZSTD_DCtx *dctx)
#define CHECK_E(f, e)
Definition: zstd_internal.h:54
static size_t ZSTD_decompress_insertDictionary(ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
#define CHECK_F(f)
Definition: fse_compress.c:661

Referenced by ZSTD_decompressMultiFrame().

◆ ZSTD_decompressBlock()

size_t ZSTD_decompressBlock ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize 
)

Definition at line 1769 of file zstd_decompress.c.

1772 {
1773  size_t dSize;
1774  ZSTD_checkContinuity(dctx, dst);
1775  dSize = ZSTD_decompressBlock_internal(dctx, dst, dstCapacity, src, srcSize, /* frame */ 0);
1776  dctx->previousDstEnd = (char*)dst + dSize;
1777  return dSize;
1778 }
const void * previousDstEnd
static void ZSTD_checkContinuity(ZSTD_DCtx *dctx, const void *dst)
static size_t ZSTD_decompressBlock_internal(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const int frame)
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

◆ ZSTD_decompressBlock_internal()

static size_t ZSTD_decompressBlock_internal ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const int  frame 
)
static

Definition at line 1715 of file zstd_decompress.c.

1718 { /* blockType == blockCompressed */
1719  const BYTE* ip = (const BYTE*)src;
1720  /* isLongOffset must be true if there are long offsets.
1721  * Offsets are long if they are larger than 2^STREAM_ACCUMULATOR_MIN.
1722  * We don't expect that to be the case in 64-bit mode.
1723  * In block mode, window size is not known, so we have to be conservative.
1724  * (note: but it could be evaluated from current-lowLimit)
1725  */
1726  ZSTD_longOffset_e const isLongOffset = (ZSTD_longOffset_e)(MEM_32bits() && (!frame || dctx->fParams.windowSize > (1ULL << STREAM_ACCUMULATOR_MIN)));
1727  DEBUGLOG(5, "ZSTD_decompressBlock_internal (size : %u)", (U32)srcSize);
1728 
1729  if (srcSize >= ZSTD_BLOCKSIZE_MAX) return ERROR(srcSize_wrong);
1730 
1731  /* Decode literals section */
1732  { size_t const litCSize = ZSTD_decodeLiteralsBlock(dctx, src, srcSize);
1733  DEBUGLOG(5, "ZSTD_decodeLiteralsBlock : %u", (U32)litCSize);
1734  if (ZSTD_isError(litCSize)) return litCSize;
1735  ip += litCSize;
1736  srcSize -= litCSize;
1737  }
1738 
1739  /* Build Decoding Tables */
1740  { int nbSeq;
1741  size_t const seqHSize = ZSTD_decodeSeqHeaders(dctx, &nbSeq, ip, srcSize);
1742  if (ZSTD_isError(seqHSize)) return seqHSize;
1743  ip += seqHSize;
1744  srcSize -= seqHSize;
1745 
1746  if ( (!frame || dctx->fParams.windowSize > (1<<24))
1747  && (nbSeq>0) ) { /* could probably use a larger nbSeq limit */
1748  U32 const shareLongOffsets = ZSTD_getLongOffsetsShare(dctx->OFTptr);
1749  U32 const minShare = MEM_64bits() ? 7 : 20; /* heuristic values, correspond to 2.73% and 7.81% */
1750  if (shareLongOffsets >= minShare)
1751  return ZSTD_decompressSequencesLong(dctx, dst, dstCapacity, ip, srcSize, nbSeq, isLongOffset);
1752  }
1753 
1754  return ZSTD_decompressSequences(dctx, dst, dstCapacity, ip, srcSize, nbSeq, isLongOffset);
1755  }
1756 }
size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx *dctx, const void *src, size_t srcSize)
ZSTD_frameHeader fParams
#define ERROR(name)
Definition: error_private.h:53
const ZSTD_seqSymbol * OFTptr
unsigned int U32
Definition: mem.h:77
MEM_STATIC unsigned MEM_32bits(void)
Definition: mem.h:110
MEM_STATIC unsigned MEM_64bits(void)
Definition: mem.h:111
static unsigned ZSTD_getLongOffsetsShare(const ZSTD_seqSymbol *offTable)
#define DEBUGLOG(l,...)
Definition: debug.h:115
ZSTD_longOffset_e
#define ULL(a, b)
Definition: format_msg.c:27
Definition: dhcpd.h:61
unsigned char BYTE
Definition: mem.h:68
GLenum src
Definition: glext.h:6340
#define STREAM_ACCUMULATOR_MIN
Definition: bitstream.h:64
size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx *dctx, int *nbSeqPtr, const void *src, size_t srcSize)
static size_t ZSTD_decompressSequencesLong(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
#define ZSTD_isError
GLenum GLenum dst
Definition: glext.h:6340
static size_t ZSTD_decompressSequences(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)

Referenced by ZSTD_decompressBlock(), ZSTD_decompressContinue(), and ZSTD_decompressFrame().

◆ ZSTD_decompressContinue()

size_t ZSTD_decompressContinue ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize 
)

ZSTD_decompressContinue() : srcSize : must be the exact nb of bytes expected (see ZSTD_nextSrcSizeToDecompress())

Returns
: nb of bytes generated into dst (necessarily <= `dstCapacity) or an error code, which can be tested using ZSTD_isError()

Definition at line 2091 of file zstd_decompress.c.

2092 {
2093  DEBUGLOG(5, "ZSTD_decompressContinue (srcSize:%u)", (U32)srcSize);
2094  /* Sanity check */
2095  if (srcSize != dctx->expected) return ERROR(srcSize_wrong); /* not allowed */
2096  if (dstCapacity) ZSTD_checkContinuity(dctx, dst);
2097 
2098  switch (dctx->stage)
2099  {
2101  assert(src != NULL);
2102  if (dctx->format == ZSTD_f_zstd1) { /* allows header */
2103  assert(srcSize >= ZSTD_FRAMEIDSIZE); /* to read skippable magic number */
2104  if ((MEM_readLE32(src) & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) { /* skippable frame */
2105  memcpy(dctx->headerBuffer, src, srcSize);
2106  dctx->expected = ZSTD_skippableHeaderSize - srcSize; /* remaining to load to get full skippable frame header */
2108  return 0;
2109  } }
2110  dctx->headerSize = ZSTD_frameHeaderSize_internal(src, srcSize, dctx->format);
2111  if (ZSTD_isError(dctx->headerSize)) return dctx->headerSize;
2112  memcpy(dctx->headerBuffer, src, srcSize);
2113  dctx->expected = dctx->headerSize - srcSize;
2115  return 0;
2116 
2118  assert(src != NULL);
2119  memcpy(dctx->headerBuffer + (dctx->headerSize - srcSize), src, srcSize);
2123  return 0;
2124 
2126  { blockProperties_t bp;
2127  size_t const cBlockSize = ZSTD_getcBlockSize(src, ZSTD_blockHeaderSize, &bp);
2128  if (ZSTD_isError(cBlockSize)) return cBlockSize;
2129  dctx->expected = cBlockSize;
2130  dctx->bType = bp.blockType;
2131  dctx->rleSize = bp.origSize;
2132  if (cBlockSize) {
2134  return 0;
2135  }
2136  /* empty block */
2137  if (bp.lastBlock) {
2138  if (dctx->fParams.checksumFlag) {
2139  dctx->expected = 4;
2140  dctx->stage = ZSTDds_checkChecksum;
2141  } else {
2142  dctx->expected = 0; /* end of frame */
2144  }
2145  } else {
2146  dctx->expected = ZSTD_blockHeaderSize; /* jump to next header */
2148  }
2149  return 0;
2150  }
2151 
2154  DEBUGLOG(5, "ZSTD_decompressContinue: case ZSTDds_decompressBlock");
2155  { size_t rSize;
2156  switch(dctx->bType)
2157  {
2158  case bt_compressed:
2159  DEBUGLOG(5, "ZSTD_decompressContinue: case bt_compressed");
2160  rSize = ZSTD_decompressBlock_internal(dctx, dst, dstCapacity, src, srcSize, /* frame */ 1);
2161  break;
2162  case bt_raw :
2163  rSize = ZSTD_copyRawBlock(dst, dstCapacity, src, srcSize);
2164  break;
2165  case bt_rle :
2166  rSize = ZSTD_setRleBlock(dst, dstCapacity, src, srcSize, dctx->rleSize);
2167  break;
2168  case bt_reserved : /* should never happen */
2169  default:
2170  return ERROR(corruption_detected);
2171  }
2172  if (ZSTD_isError(rSize)) return rSize;
2173  DEBUGLOG(5, "ZSTD_decompressContinue: decoded size from block : %u", (U32)rSize);
2174  dctx->decodedSize += rSize;
2175  if (dctx->fParams.checksumFlag) XXH64_update(&dctx->xxhState, dst, rSize);
2176 
2177  if (dctx->stage == ZSTDds_decompressLastBlock) { /* end of frame */
2178  DEBUGLOG(4, "ZSTD_decompressContinue: decoded size from frame : %u", (U32)dctx->decodedSize);
2179  if (dctx->fParams.frameContentSize != ZSTD_CONTENTSIZE_UNKNOWN) {
2180  if (dctx->decodedSize != dctx->fParams.frameContentSize) {
2181  return ERROR(corruption_detected);
2182  } }
2183  if (dctx->fParams.checksumFlag) { /* another round for frame checksum */
2184  dctx->expected = 4;
2185  dctx->stage = ZSTDds_checkChecksum;
2186  } else {
2187  dctx->expected = 0; /* ends here */
2189  }
2190  } else {
2193  dctx->previousDstEnd = (char*)dst + rSize;
2194  }
2195  return rSize;
2196  }
2197 
2198  case ZSTDds_checkChecksum:
2199  assert(srcSize == 4); /* guaranteed by dctx->expected */
2200  { U32 const h32 = (U32)XXH64_digest(&dctx->xxhState);
2201  U32 const check32 = MEM_readLE32(src);
2202  DEBUGLOG(4, "ZSTD_decompressContinue: checksum : calculated %08X :: %08X read", h32, check32);
2203  if (check32 != h32) return ERROR(checksum_wrong);
2204  dctx->expected = 0;
2206  return 0;
2207  }
2208 
2210  assert(src != NULL);
2211  assert(srcSize <= ZSTD_skippableHeaderSize);
2212  memcpy(dctx->headerBuffer + (ZSTD_skippableHeaderSize - srcSize), src, srcSize); /* complete skippable header */
2213  dctx->expected = MEM_readLE32(dctx->headerBuffer + ZSTD_FRAMEIDSIZE); /* note : dctx->expected can grow seriously large, beyond local buffer size */
2214  dctx->stage = ZSTDds_skipFrame;
2215  return 0;
2216 
2217  case ZSTDds_skipFrame:
2218  dctx->expected = 0;
2220  return 0;
2221 
2222  default:
2223  return ERROR(GENERIC); /* impossible */
2224  }
2225 }
const void * previousDstEnd
blockType_e bType
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
blockType_e blockType
ZSTD_frameHeader fParams
#define ERROR(name)
Definition: error_private.h:53
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
Definition: mem.h:273
unsigned int U32
Definition: mem.h:77
XXH64_state_t xxhState
#define assert(x)
Definition: debug.h:53
static void ZSTD_checkContinuity(ZSTD_DCtx *dctx, const void *dst)
ZSTD_format_e format
XXH_PUBLIC_API unsigned long long XXH64_digest(const XXH64_state_t *state_in)
Definition: xxhash.c:844
#define DEBUGLOG(l,...)
Definition: debug.h:115
static size_t ZSTD_decompressBlock_internal(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const int frame)
static const size_t ZSTD_blockHeaderSize
Definition: zstd_internal.h:85
smooth NULL
Definition: ftsmooth.c:416
#define CHECK_F(f)
Definition: fse_compress.c:661
BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX]
static size_t ZSTD_decodeFrameHeader(ZSTD_DCtx *dctx, const void *src, size_t headerSize)
XXH_PUBLIC_API XXH_errorcode XXH64_update(XXH64_state_t *state_in, const void *input, size_t len)
Definition: xxhash.c:780
ZSTD_dStage stage
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum src
Definition: glext.h:6340
static size_t ZSTD_setRleBlock(void *dst, size_t dstCapacity, const void *src, size_t srcSize, size_t regenSize)
#define ZSTD_isError
#define ZSTD_FRAMEIDSIZE
Definition: zstd_internal.h:82
GLenum GLenum dst
Definition: glext.h:6340
static size_t ZSTD_copyRawBlock(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
size_t ZSTD_getcBlockSize(const void *src, size_t srcSize, blockProperties_t *bpPtr)
static size_t ZSTD_frameHeaderSize_internal(const void *src, size_t srcSize, ZSTD_format_e format)

Referenced by ZSTD_decompressStream().

◆ ZSTD_decompressDCtx()

size_t ZSTD_decompressDCtx ( ZSTD_DCtx ctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize 
)

ZSTD_decompressDCtx() : Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx())

Definition at line 2034 of file zstd_decompress.c.

2035 {
2036  return ZSTD_decompress_usingDict(dctx, dst, dstCapacity, src, srcSize, NULL, 0);
2037 }
smooth NULL
Definition: ftsmooth.c:416
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
size_t ZSTD_decompress_usingDict(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize)

Referenced by ZSTD_decompress().

◆ ZSTD_decompressFrame()

static size_t ZSTD_decompressFrame ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
const void **  srcPtr,
size_t srcSizePtr 
)
static

ZSTD_decompressFrame() : @dctx must be properly initialized

Definition at line 1853 of file zstd_decompress.c.

1856 {
1857  const BYTE* ip = (const BYTE*)(*srcPtr);
1858  BYTE* const ostart = (BYTE* const)dst;
1859  BYTE* const oend = ostart + dstCapacity;
1860  BYTE* op = ostart;
1861  size_t remainingSize = *srcSizePtr;
1862 
1863  /* check */
1864  if (remainingSize < ZSTD_frameHeaderSize_min+ZSTD_blockHeaderSize)
1865  return ERROR(srcSize_wrong);
1866 
1867  /* Frame Header */
1868  { size_t const frameHeaderSize = ZSTD_frameHeaderSize(ip, ZSTD_frameHeaderSize_prefix);
1869  if (ZSTD_isError(frameHeaderSize)) return frameHeaderSize;
1870  if (remainingSize < frameHeaderSize+ZSTD_blockHeaderSize)
1871  return ERROR(srcSize_wrong);
1872  CHECK_F( ZSTD_decodeFrameHeader(dctx, ip, frameHeaderSize) );
1873  ip += frameHeaderSize; remainingSize -= frameHeaderSize;
1874  }
1875 
1876  /* Loop on each block */
1877  while (1) {
1878  size_t decodedSize;
1879  blockProperties_t blockProperties;
1880  size_t const cBlockSize = ZSTD_getcBlockSize(ip, remainingSize, &blockProperties);
1881  if (ZSTD_isError(cBlockSize)) return cBlockSize;
1882 
1884  remainingSize -= ZSTD_blockHeaderSize;
1885  if (cBlockSize > remainingSize) return ERROR(srcSize_wrong);
1886 
1887  switch(blockProperties.blockType)
1888  {
1889  case bt_compressed:
1890  decodedSize = ZSTD_decompressBlock_internal(dctx, op, oend-op, ip, cBlockSize, /* frame */ 1);
1891  break;
1892  case bt_raw :
1893  decodedSize = ZSTD_copyRawBlock(op, oend-op, ip, cBlockSize);
1894  break;
1895  case bt_rle :
1896  decodedSize = ZSTD_generateNxBytes(op, oend-op, *ip, blockProperties.origSize);
1897  break;
1898  case bt_reserved :
1899  default:
1900  return ERROR(corruption_detected);
1901  }
1902 
1903  if (ZSTD_isError(decodedSize)) return decodedSize;
1904  if (dctx->fParams.checksumFlag)
1905  XXH64_update(&dctx->xxhState, op, decodedSize);
1906  op += decodedSize;
1907  ip += cBlockSize;
1908  remainingSize -= cBlockSize;
1909  if (blockProperties.lastBlock) break;
1910  }
1911 
1912  if (dctx->fParams.frameContentSize != ZSTD_CONTENTSIZE_UNKNOWN) {
1913  if ((U64)(op-ostart) != dctx->fParams.frameContentSize) {
1914  return ERROR(corruption_detected);
1915  } }
1916  if (dctx->fParams.checksumFlag) { /* Frame content checksum verification */
1917  U32 const checkCalc = (U32)XXH64_digest(&dctx->xxhState);
1918  U32 checkRead;
1919  if (remainingSize<4) return ERROR(checksum_wrong);
1920  checkRead = MEM_readLE32(ip);
1921  if (checkRead != checkCalc) return ERROR(checksum_wrong);
1922  ip += 4;
1923  remainingSize -= 4;
1924  }
1925 
1926  /* Allow caller to get size read */
1927  *srcPtr = ip;
1928  *srcSizePtr = remainingSize;
1929  return op-ostart;
1930 }
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
blockType_e blockType
ZSTD_frameHeader fParams
size_t ZSTD_frameHeaderSize(const void *src, size_t srcSize)
#define ERROR(name)
Definition: error_private.h:53
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
Definition: mem.h:273
unsigned int U32
Definition: mem.h:77
XXH64_state_t xxhState
XXH_PUBLIC_API unsigned long long XXH64_digest(const XXH64_state_t *state_in)
Definition: xxhash.c:844
static size_t ZSTD_decompressBlock_internal(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const int frame)
static const size_t ZSTD_blockHeaderSize
Definition: zstd_internal.h:85
int ip[4]
Definition: rtl.c:1176
#define CHECK_F(f)
Definition: fse_compress.c:661
static size_t ZSTD_decodeFrameHeader(ZSTD_DCtx *dctx, const void *src, size_t headerSize)
Definition: dhcpd.h:61
XXH_PUBLIC_API XXH_errorcode XXH64_update(XXH64_state_t *state_in, const void *input, size_t len)
Definition: xxhash.c:780
static size_t ZSTD_generateNxBytes(void *dst, size_t dstCapacity, BYTE value, size_t length)
unsigned char BYTE
Definition: mem.h:68
#define ZSTD_isError
unsigned long long U64
Definition: mem.h:81
GLenum GLenum dst
Definition: glext.h:6340
static size_t ZSTD_copyRawBlock(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
size_t ZSTD_getcBlockSize(const void *src, size_t srcSize, blockProperties_t *bpPtr)
UINT op
Definition: effect.c:223

Referenced by ZSTD_decompressMultiFrame().

◆ ZSTD_decompressMultiFrame()

static size_t ZSTD_decompressMultiFrame ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const void dict,
size_t  dictSize,
const ZSTD_DDict ddict 
)
static

Definition at line 1932 of file zstd_decompress.c.

1937 {
1938  void* const dststart = dst;
1939  int moreThan1Frame = 0;
1940 
1941  DEBUGLOG(5, "ZSTD_decompressMultiFrame");
1942  assert(dict==NULL || ddict==NULL); /* either dict or ddict set, not both */
1943 
1944  if (ddict) {
1945  dict = ZSTD_DDictDictContent(ddict);
1946  dictSize = ZSTD_DDictDictSize(ddict);
1947  }
1948 
1949  while (srcSize >= ZSTD_frameHeaderSize_prefix) {
1950 
1951 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
1952  if (ZSTD_isLegacy(src, srcSize)) {
1953  size_t decodedSize;
1954  size_t const frameSize = ZSTD_findFrameCompressedSizeLegacy(src, srcSize);
1955  if (ZSTD_isError(frameSize)) return frameSize;
1956  /* legacy support is not compatible with static dctx */
1957  if (dctx->staticSize) return ERROR(memory_allocation);
1958 
1959  decodedSize = ZSTD_decompressLegacy(dst, dstCapacity, src, frameSize, dict, dictSize);
1960 
1961  dst = (BYTE*)dst + decodedSize;
1962  dstCapacity -= decodedSize;
1963 
1964  src = (const BYTE*)src + frameSize;
1965  srcSize -= frameSize;
1966 
1967  continue;
1968  }
1969 #endif
1970 
1971  { U32 const magicNumber = MEM_readLE32(src);
1972  DEBUGLOG(4, "reading magic number %08X (expecting %08X)",
1973  (U32)magicNumber, (U32)ZSTD_MAGICNUMBER);
1974  if ((magicNumber & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) {
1975  size_t skippableSize;
1976  if (srcSize < ZSTD_skippableHeaderSize)
1977  return ERROR(srcSize_wrong);
1978  skippableSize = MEM_readLE32((const BYTE*)src + ZSTD_FRAMEIDSIZE)
1979  + ZSTD_skippableHeaderSize;
1980  if (srcSize < skippableSize) return ERROR(srcSize_wrong);
1981 
1982  src = (const BYTE *)src + skippableSize;
1983  srcSize -= skippableSize;
1984  continue;
1985  } }
1986 
1987  if (ddict) {
1988  /* we were called from ZSTD_decompress_usingDDict */
1990  } else {
1991  /* this will initialize correctly with no dict if dict == NULL, so
1992  * use this in all cases but ddict */
1993  CHECK_F(ZSTD_decompressBegin_usingDict(dctx, dict, dictSize));
1994  }
1995  ZSTD_checkContinuity(dctx, dst);
1996 
1997  { const size_t res = ZSTD_decompressFrame(dctx, dst, dstCapacity,
1998  &src, &srcSize);
2000  && (moreThan1Frame==1) ) {
2001  /* at least one frame successfully completed,
2002  * but following bytes are garbage :
2003  * it's more likely to be a srcSize error,
2004  * specifying more bytes than compressed size of frame(s).
2005  * This error message replaces ERROR(prefix_unknown),
2006  * which would be confusing, as the first header is actually correct.
2007  * Note that one could be unlucky, it might be a corruption error instead,
2008  * happening right at the place where we expect zstd magic bytes.
2009  * But this is _much_ less likely than a srcSize field error. */
2010  return ERROR(srcSize_wrong);
2011  }
2012  if (ZSTD_isError(res)) return res;
2013  /* no need to bound check, ZSTD_decompressFrame already has */
2014  dst = (BYTE*)dst + res;
2015  dstCapacity -= res;
2016  }
2017  moreThan1Frame = 1;
2018  } /* while (srcSize >= ZSTD_frameHeaderSize_prefix) */
2019 
2020  if (srcSize) return ERROR(srcSize_wrong); /* input not entirely consumed */
2021 
2022  return (BYTE*)dst - (BYTE*)dststart;
2023 }
ZSTD_ErrorCode ZSTD_getErrorCode(size_t code)
Definition: zstd_common.c:43
#define ERROR(name)
Definition: error_private.h:53
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
Definition: mem.h:273
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
static void ZSTD_checkContinuity(ZSTD_DCtx *dctx, const void *dst)
size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
#define DEBUGLOG(l,...)
Definition: debug.h:115
static size_t ZSTD_DDictDictSize(const ZSTD_DDict *ddict)
static const void * ZSTD_DDictDictContent(const ZSTD_DDict *ddict)
size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
smooth NULL
Definition: ftsmooth.c:416
#define CHECK_F(f)
Definition: fse_compress.c:661
static size_t ZSTD_decompressFrame(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void **srcPtr, size_t *srcSizePtr)
unsigned char BYTE
Definition: mem.h:68
GLenum src
Definition: glext.h:6340
#define ZSTD_isError
#define ZSTD_FRAMEIDSIZE
Definition: zstd_internal.h:82
GLenum GLenum dst
Definition: glext.h:6340
GLuint res
Definition: glext.h:9613

Referenced by ZSTD_decompress_usingDDict(), and ZSTD_decompress_usingDict().

◆ ZSTD_decompressSequences()

static size_t ZSTD_decompressSequences ( ZSTD_DCtx dctx,
void dst,
size_t  maxDstSize,
const void seqStart,
size_t  seqSize,
int  nbSeq,
const ZSTD_longOffset_e  isLongOffset 
)
static

Definition at line 1662 of file zstd_decompress.c.

1665 {
1666  DEBUGLOG(5, "ZSTD_decompressSequences");
1667 #if DYNAMIC_BMI2
1668  if (dctx->bmi2) {
1669  return ZSTD_decompressSequences_bmi2(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset);
1670  }
1671 #endif
1672  return ZSTD_decompressSequences_default(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset);
1673 }
#define DEBUGLOG(l,...)
Definition: debug.h:115
static size_t ZSTD_decompressSequences_default(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_decompressBlock_internal().

◆ ZSTD_decompressSequences_body()

FORCE_INLINE_TEMPLATE size_t ZSTD_decompressSequences_body ( ZSTD_DCtx dctx,
void dst,
size_t  maxDstSize,
const void seqStart,
size_t  seqSize,
int  nbSeq,
const ZSTD_longOffset_e  isLongOffset 
)

Definition at line 1403 of file zstd_decompress.c.

1407 {
1408  const BYTE* ip = (const BYTE*)seqStart;
1409  const BYTE* const iend = ip + seqSize;
1410  BYTE* const ostart = (BYTE* const)dst;
1411  BYTE* const oend = ostart + maxDstSize;
1412  BYTE* op = ostart;
1413  const BYTE* litPtr = dctx->litPtr;
1414  const BYTE* const litEnd = litPtr + dctx->litSize;
1415  const BYTE* const prefixStart = (const BYTE*) (dctx->prefixStart);
1416  const BYTE* const vBase = (const BYTE*) (dctx->virtualStart);
1417  const BYTE* const dictEnd = (const BYTE*) (dctx->dictEnd);
1418  DEBUGLOG(5, "ZSTD_decompressSequences_body");
1419 
1420  /* Regen sequences */
1421  if (nbSeq) {
1422  seqState_t seqState;
1423  dctx->fseEntropy = 1;
1424  { U32 i; for (i=0; i<ZSTD_REP_NUM; i++) seqState.prevOffset[i] = dctx->entropy.rep[i]; }
1425  CHECK_E(BIT_initDStream(&seqState.DStream, ip, iend-ip), corruption_detected);
1426  ZSTD_initFseState(&seqState.stateLL, &seqState.DStream, dctx->LLTptr);
1427  ZSTD_initFseState(&seqState.stateOffb, &seqState.DStream, dctx->OFTptr);
1428  ZSTD_initFseState(&seqState.stateML, &seqState.DStream, dctx->MLTptr);
1429 
1430  for ( ; (BIT_reloadDStream(&(seqState.DStream)) <= BIT_DStream_completed) && nbSeq ; ) {
1431  nbSeq--;
1432  { seq_t const sequence = ZSTD_decodeSequence(&seqState, isLongOffset);
1433  size_t const oneSeqSize = ZSTD_execSequence(op, oend, sequence, &litPtr, litEnd, prefixStart, vBase, dictEnd);
1434  DEBUGLOG(6, "regenerated sequence size : %u", (U32)oneSeqSize);
1435  if (ZSTD_isError(oneSeqSize)) return oneSeqSize;
1436  op += oneSeqSize;
1437  } }
1438 
1439  /* check if reached exact end */
1440  DEBUGLOG(5, "ZSTD_decompressSequences_body: after decode loop, remaining nbSeq : %i", nbSeq);
1441  if (nbSeq) return ERROR(corruption_detected);
1442  /* save reps for next block */
1443  { U32 i; for (i=0; i<ZSTD_REP_NUM; i++) dctx->entropy.rep[i] = (U32)(seqState.prevOffset[i]); }
1444  }
1445 
1446  /* last literal segment */
1447  { size_t const lastLLSize = litEnd - litPtr;
1448  if (lastLLSize > (size_t)(oend-op)) return ERROR(dstSize_tooSmall);
1449  memcpy(op, litPtr, lastLLSize);
1450  op += lastLLSize;
1451  }
1452 
1453  return op-ostart;
1454 }
BIT_DStream_t DStream
U32 rep[ZSTD_REP_NUM]
#define ERROR(name)
Definition: error_private.h:53
const ZSTD_seqSymbol * OFTptr
unsigned int U32
Definition: mem.h:77
MEM_STATIC size_t BIT_initDStream(BIT_DStream_t *bitD, const void *srcBuffer, size_t srcSize)
Definition: bitstream.h:287
const void * dictEnd
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t *bitD)
Definition: bitstream.h:414
ZSTD_fseState stateOffb
ZSTD_fseState stateML
#define CHECK_E(f, e)
Definition: zstd_internal.h:54
#define DEBUGLOG(l,...)
Definition: debug.h:115
const void * virtualStart
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
const void * prefixStart
FORCE_INLINE_TEMPLATE seq_t ZSTD_decodeSequence(seqState_t *seqState, const ZSTD_longOffset_e longOffsets)
const ZSTD_seqSymbol * LLTptr
static void ZSTD_initFseState(ZSTD_fseState *DStatePtr, BIT_DStream_t *bitD, const ZSTD_seqSymbol *dt)
const ZSTD_seqSymbol * MLTptr
Definition: dhcpd.h:61
ZSTD_entropyDTables_t entropy
static struct message * sequence
Definition: subclass.c:48
ZSTD_fseState stateLL
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define ZSTD_isError
HINT_INLINE size_t ZSTD_execSequence(BYTE *op, BYTE *const oend, seq_t sequence, const BYTE **litPtr, const BYTE *const litLimit, const BYTE *const prefixStart, const BYTE *const virtualStart, const BYTE *const dictEnd)
GLenum GLenum dst
Definition: glext.h:6340
size_t prevOffset[ZSTD_REP_NUM]
const BYTE * litPtr
UINT op
Definition: effect.c:223
#define ZSTD_REP_NUM
Definition: zstd_internal.h:62

Referenced by ZSTD_decompressSequences_default().

◆ ZSTD_decompressSequences_default()

static size_t ZSTD_decompressSequences_default ( ZSTD_DCtx dctx,
void dst,
size_t  maxDstSize,
const void seqStart,
size_t  seqSize,
int  nbSeq,
const ZSTD_longOffset_e  isLongOffset 
)
static

Definition at line 1457 of file zstd_decompress.c.

1461 {
1462  return ZSTD_decompressSequences_body(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset);
1463 }
FORCE_INLINE_TEMPLATE size_t ZSTD_decompressSequences_body(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_decompressSequences().

◆ ZSTD_decompressSequencesLong()

static size_t ZSTD_decompressSequencesLong ( ZSTD_DCtx dctx,
void dst,
size_t  maxDstSize,
const void seqStart,
size_t  seqSize,
int  nbSeq,
const ZSTD_longOffset_e  isLongOffset 
)
static

Definition at line 1675 of file zstd_decompress.c.

1679 {
1680  DEBUGLOG(5, "ZSTD_decompressSequencesLong");
1681 #if DYNAMIC_BMI2
1682  if (dctx->bmi2) {
1683  return ZSTD_decompressSequencesLong_bmi2(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset);
1684  }
1685 #endif
1686  return ZSTD_decompressSequencesLong_default(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset);
1687 }
#define DEBUGLOG(l,...)
Definition: debug.h:115
GLenum GLenum dst
Definition: glext.h:6340
static size_t ZSTD_decompressSequencesLong_default(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)

Referenced by ZSTD_decompressBlock_internal().

◆ ZSTD_decompressSequencesLong_body()

FORCE_INLINE_TEMPLATE size_t ZSTD_decompressSequencesLong_body ( ZSTD_DCtx dctx,
void dst,
size_t  maxDstSize,
const void seqStart,
size_t  seqSize,
int  nbSeq,
const ZSTD_longOffset_e  isLongOffset 
)

Definition at line 1546 of file zstd_decompress.c.

1551 {
1552  const BYTE* ip = (const BYTE*)seqStart;
1553  const BYTE* const iend = ip + seqSize;
1554  BYTE* const ostart = (BYTE* const)dst;
1555  BYTE* const oend = ostart + maxDstSize;
1556  BYTE* op = ostart;
1557  const BYTE* litPtr = dctx->litPtr;
1558  const BYTE* const litEnd = litPtr + dctx->litSize;
1559  const BYTE* const prefixStart = (const BYTE*) (dctx->prefixStart);
1560  const BYTE* const dictStart = (const BYTE*) (dctx->virtualStart);
1561  const BYTE* const dictEnd = (const BYTE*) (dctx->dictEnd);
1562 
1563  /* Regen sequences */
1564  if (nbSeq) {
1565 #define STORED_SEQS 4
1566 #define STOSEQ_MASK (STORED_SEQS-1)
1567 #define ADVANCED_SEQS 4
1569  int const seqAdvance = MIN(nbSeq, ADVANCED_SEQS);
1570  seqState_t seqState;
1571  int seqNb;
1572  dctx->fseEntropy = 1;
1573  { U32 i; for (i=0; i<ZSTD_REP_NUM; i++) seqState.prevOffset[i] = dctx->entropy.rep[i]; }
1574  seqState.prefixStart = prefixStart;
1575  seqState.pos = (size_t)(op-prefixStart);
1576  seqState.dictEnd = dictEnd;
1577  CHECK_E(BIT_initDStream(&seqState.DStream, ip, iend-ip), corruption_detected);
1578  ZSTD_initFseState(&seqState.stateLL, &seqState.DStream, dctx->LLTptr);
1579  ZSTD_initFseState(&seqState.stateOffb, &seqState.DStream, dctx->OFTptr);
1580  ZSTD_initFseState(&seqState.stateML, &seqState.DStream, dctx->MLTptr);
1581 
1582  /* prepare in advance */
1583  for (seqNb=0; (BIT_reloadDStream(&seqState.DStream) <= BIT_DStream_completed) && (seqNb<seqAdvance); seqNb++) {
1584  sequences[seqNb] = ZSTD_decodeSequenceLong(&seqState, isLongOffset);
1585  }
1586  if (seqNb<seqAdvance) return ERROR(corruption_detected);
1587 
1588  /* decode and decompress */
1589  for ( ; (BIT_reloadDStream(&(seqState.DStream)) <= BIT_DStream_completed) && (seqNb<nbSeq) ; seqNb++) {
1590  seq_t const sequence = ZSTD_decodeSequenceLong(&seqState, isLongOffset);
1591  size_t const oneSeqSize = ZSTD_execSequenceLong(op, oend, sequences[(seqNb-ADVANCED_SEQS) & STOSEQ_MASK], &litPtr, litEnd, prefixStart, dictStart, dictEnd);
1592  if (ZSTD_isError(oneSeqSize)) return oneSeqSize;
1593  PREFETCH(sequence.match); /* note : it's safe to invoke PREFETCH() on any memory address, including invalid ones */
1594  sequences[seqNb&STOSEQ_MASK] = sequence;
1595  op += oneSeqSize;
1596  }
1597  if (seqNb<nbSeq) return ERROR(corruption_detected);
1598 
1599  /* finish queue */
1600  seqNb -= seqAdvance;
1601  for ( ; seqNb<nbSeq ; seqNb++) {
1602  size_t const oneSeqSize = ZSTD_execSequenceLong(op, oend, sequences[seqNb&STOSEQ_MASK], &litPtr, litEnd, prefixStart, dictStart, dictEnd);
1603  if (ZSTD_isError(oneSeqSize)) return oneSeqSize;
1604  op += oneSeqSize;
1605  }
1606 
1607  /* save reps for next block */
1608  { U32 i; for (i=0; i<ZSTD_REP_NUM; i++) dctx->entropy.rep[i] = (U32)(seqState.prevOffset[i]); }
1609 #undef STORED_SEQS
1610 #undef STOSEQ_MASK
1611 #undef ADVANCED_SEQS
1612  }
1613 
1614  /* last literal segment */
1615  { size_t const lastLLSize = litEnd - litPtr;
1616  if (lastLLSize > (size_t)(oend-op)) return ERROR(dstSize_tooSmall);
1617  memcpy(op, litPtr, lastLLSize);
1618  op += lastLLSize;
1619  }
1620 
1621  return op-ostart;
1622 }
const BYTE * dictEnd
BIT_DStream_t DStream
#define ADVANCED_SEQS
U32 rep[ZSTD_REP_NUM]
#define ERROR(name)
Definition: error_private.h:53
const ZSTD_seqSymbol * OFTptr
const BYTE * prefixStart
unsigned int U32
Definition: mem.h:77
MEM_STATIC size_t BIT_initDStream(BIT_DStream_t *bitD, const void *srcBuffer, size_t srcSize)
Definition: bitstream.h:287
#define PREFETCH(ptr)
Definition: compiler.h:108
const void * dictEnd
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t *bitD)
Definition: bitstream.h:414
ZSTD_fseState stateOffb
ZSTD_fseState stateML
T MIN(T a, T b)
Definition: polytest.cpp:79
#define CHECK_E(f, e)
Definition: zstd_internal.h:54
const void * virtualStart
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
const void * prefixStart
const ZSTD_seqSymbol * LLTptr
static void ZSTD_initFseState(ZSTD_fseState *DStatePtr, BIT_DStream_t *bitD, const ZSTD_seqSymbol *dt)
const ZSTD_seqSymbol * MLTptr
#define STOSEQ_MASK
__kernel_size_t size_t
Definition: linux.h:237
Definition: dhcpd.h:61
ZSTD_entropyDTables_t entropy
static struct message * sequence
Definition: subclass.c:48
ZSTD_fseState stateLL
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
static struct msg_sequence * sequences[NUM_MSG_SEQUENCES]
Definition: button.c:54
#define ZSTD_isError
#define STORED_SEQS
GLenum GLenum dst
Definition: glext.h:6340
size_t prevOffset[ZSTD_REP_NUM]
const BYTE * litPtr
UINT op
Definition: effect.c:223
HINT_INLINE size_t ZSTD_execSequenceLong(BYTE *op, BYTE *const oend, seq_t sequence, const BYTE **litPtr, const BYTE *const litLimit, const BYTE *const prefixStart, const BYTE *const dictStart, const BYTE *const dictEnd)
#define ZSTD_REP_NUM
Definition: zstd_internal.h:62
FORCE_INLINE_TEMPLATE seq_t ZSTD_decodeSequenceLong(seqState_t *seqState, ZSTD_longOffset_e const longOffsets)

Referenced by ZSTD_decompressSequencesLong_default().

◆ ZSTD_decompressSequencesLong_default()

static size_t ZSTD_decompressSequencesLong_default ( ZSTD_DCtx dctx,
void dst,
size_t  maxDstSize,
const void seqStart,
size_t  seqSize,
int  nbSeq,
const ZSTD_longOffset_e  isLongOffset 
)
static

Definition at line 1625 of file zstd_decompress.c.

1629 {
1630  return ZSTD_decompressSequencesLong_body(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset);
1631 }
FORCE_INLINE_TEMPLATE size_t ZSTD_decompressSequencesLong_body(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_decompressSequencesLong().

◆ ZSTD_decompressStream()

size_t ZSTD_decompressStream ( ZSTD_DStream zds,
ZSTD_outBuffer output,
ZSTD_inBuffer input 
)

Definition at line 2823 of file zstd_decompress.c.

2824 {
2825  const char* const istart = (const char*)(input->src) + input->pos;
2826  const char* const iend = (const char*)(input->src) + input->size;
2827  const char* ip = istart;
2828  char* const ostart = (char*)(output->dst) + output->pos;
2829  char* const oend = (char*)(output->dst) + output->size;
2830  char* op = ostart;
2831  U32 someMoreWork = 1;
2832 
2833  DEBUGLOG(5, "ZSTD_decompressStream");
2834  if (input->pos > input->size) { /* forbidden */
2835  DEBUGLOG(5, "in: pos: %u vs size: %u",
2836  (U32)input->pos, (U32)input->size);
2837  return ERROR(srcSize_wrong);
2838  }
2839  if (output->pos > output->size) { /* forbidden */
2840  DEBUGLOG(5, "out: pos: %u vs size: %u",
2841  (U32)output->pos, (U32)output->size);
2842  return ERROR(dstSize_tooSmall);
2843  }
2844  DEBUGLOG(5, "input size : %u", (U32)(input->size - input->pos));
2845 
2846  while (someMoreWork) {
2847  switch(zds->streamStage)
2848  {
2849  case zdss_init :
2850  DEBUGLOG(5, "stage zdss_init => transparent reset ");
2851  ZSTD_resetDStream(zds); /* transparent reset on starting decoding a new frame */
2852  /* fall-through */
2853 
2854  case zdss_loadHeader :
2855  DEBUGLOG(5, "stage zdss_loadHeader (srcSize : %u)", (U32)(iend - ip));
2856 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
2857  if (zds->legacyVersion) {
2858  /* legacy support is incompatible with static dctx */
2859  if (zds->staticSize) return ERROR(memory_allocation);
2860  { size_t const hint = ZSTD_decompressLegacyStream(zds->legacyContext, zds->legacyVersion, output, input);
2861  if (hint==0) zds->streamStage = zdss_init;
2862  return hint;
2863  } }
2864 #endif
2865  { size_t const hSize = ZSTD_getFrameHeader_advanced(&zds->fParams, zds->headerBuffer, zds->lhSize, zds->format);
2866  DEBUGLOG(5, "header size : %u", (U32)hSize);
2867  if (ZSTD_isError(hSize)) {
2868 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
2869  U32 const legacyVersion = ZSTD_isLegacy(istart, iend-istart);
2870  if (legacyVersion) {
2871  const void* const dict = zds->ddict ? zds->ddict->dictContent : NULL;
2872  size_t const dictSize = zds->ddict ? zds->ddict->dictSize : 0;
2873  DEBUGLOG(5, "ZSTD_decompressStream: detected legacy version v0.%u", legacyVersion);
2874  /* legacy support is incompatible with static dctx */
2875  if (zds->staticSize) return ERROR(memory_allocation);
2876  CHECK_F(ZSTD_initLegacyStream(&zds->legacyContext,
2877  zds->previousLegacyVersion, legacyVersion,
2878  dict, dictSize));
2879  zds->legacyVersion = zds->previousLegacyVersion = legacyVersion;
2880  { size_t const hint = ZSTD_decompressLegacyStream(zds->legacyContext, legacyVersion, output, input);
2881  if (hint==0) zds->streamStage = zdss_init; /* or stay in stage zdss_loadHeader */
2882  return hint;
2883  } }
2884 #endif
2885  return hSize; /* error */
2886  }
2887  if (hSize != 0) { /* need more input */
2888  size_t const toLoad = hSize - zds->lhSize; /* if hSize!=0, hSize > zds->lhSize */
2889  size_t const remainingInput = (size_t)(iend-ip);
2890  assert(iend >= ip);
2891  if (toLoad > remainingInput) { /* not enough input to load full header */
2892  if (remainingInput > 0) {
2893  memcpy(zds->headerBuffer + zds->lhSize, ip, remainingInput);
2894  zds->lhSize += remainingInput;
2895  }
2896  input->pos = input->size;
2897  return (MAX(ZSTD_frameHeaderSize_min, hSize) - zds->lhSize) + ZSTD_blockHeaderSize; /* remaining header bytes + next block header */
2898  }
2899  assert(ip != NULL);
2900  memcpy(zds->headerBuffer + zds->lhSize, ip, toLoad); zds->lhSize = hSize; ip += toLoad;
2901  break;
2902  } }
2903 
2904  /* check for single-pass mode opportunity */
2905  if (zds->fParams.frameContentSize && zds->fParams.windowSize /* skippable frame if == 0 */
2906  && (U64)(size_t)(oend-op) >= zds->fParams.frameContentSize) {
2907  size_t const cSize = ZSTD_findFrameCompressedSize(istart, iend-istart);
2908  if (cSize <= (size_t)(iend-istart)) {
2909  /* shortcut : using single-pass mode */
2910  size_t const decompressedSize = ZSTD_decompress_usingDDict(zds, op, oend-op, istart, cSize, zds->ddict);
2911  if (ZSTD_isError(decompressedSize)) return decompressedSize;
2912  DEBUGLOG(4, "shortcut to single-pass ZSTD_decompress_usingDDict()")
2913  ip = istart + cSize;
2914  op += decompressedSize;
2915  zds->expected = 0;
2916  zds->streamStage = zdss_init;
2917  someMoreWork = 0;
2918  break;
2919  } }
2920 
2921  /* Consume header (see ZSTDds_decodeFrameHeader) */
2922  DEBUGLOG(4, "Consume header");
2923  CHECK_F(ZSTD_decompressBegin_usingDDict(zds, zds->ddict));
2924 
2925  if ((MEM_readLE32(zds->headerBuffer) & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) { /* skippable frame */
2926  zds->expected = MEM_readLE32(zds->headerBuffer + ZSTD_FRAMEIDSIZE);
2927  zds->stage = ZSTDds_skipFrame;
2928  } else {
2932  }
2933 
2934  /* control buffer memory usage */
2935  DEBUGLOG(4, "Control max memory usage (%u KB <= max %u KB)",
2936  (U32)(zds->fParams.windowSize >>10),
2937  (U32)(zds->maxWindowSize >> 10) );
2938  zds->fParams.windowSize = MAX(zds->fParams.windowSize, 1U << ZSTD_WINDOWLOG_ABSOLUTEMIN);
2939  if (zds->fParams.windowSize > zds->maxWindowSize) return ERROR(frameParameter_windowTooLarge);
2940 
2941  /* Adapt buffer sizes to frame header instructions */
2942  { size_t const neededInBuffSize = MAX(zds->fParams.blockSizeMax, 4 /* frame checksum */);
2943  size_t const neededOutBuffSize = ZSTD_decodingBufferSize_min(zds->fParams.windowSize, zds->fParams.frameContentSize);
2944  if ((zds->inBuffSize < neededInBuffSize) || (zds->outBuffSize < neededOutBuffSize)) {
2945  size_t const bufferSize = neededInBuffSize + neededOutBuffSize;
2946  DEBUGLOG(4, "inBuff : from %u to %u",
2947  (U32)zds->inBuffSize, (U32)neededInBuffSize);
2948  DEBUGLOG(4, "outBuff : from %u to %u",
2949  (U32)zds->outBuffSize, (U32)neededOutBuffSize);
2950  if (zds->staticSize) { /* static DCtx */
2951  DEBUGLOG(4, "staticSize : %u", (U32)zds->staticSize);
2952  assert(zds->staticSize >= sizeof(ZSTD_DCtx)); /* controlled at init */
2953  if (bufferSize > zds->staticSize - sizeof(ZSTD_DCtx))
2954  return ERROR(memory_allocation);
2955  } else {
2956  ZSTD_free(zds->inBuff, zds->customMem);
2957  zds->inBuffSize = 0;
2958  zds->outBuffSize = 0;
2959  zds->inBuff = (char*)ZSTD_malloc(bufferSize, zds->customMem);
2960  if (zds->inBuff == NULL) return ERROR(memory_allocation);
2961  }
2962  zds->inBuffSize = neededInBuffSize;
2963  zds->outBuff = zds->inBuff + zds->inBuffSize;
2964  zds->outBuffSize = neededOutBuffSize;
2965  } }
2966  zds->streamStage = zdss_read;
2967  /* fall-through */
2968 
2969  case zdss_read:
2970  DEBUGLOG(5, "stage zdss_read");
2971  { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds);
2972  DEBUGLOG(5, "neededInSize = %u", (U32)neededInSize);
2973  if (neededInSize==0) { /* end of frame */
2974  zds->streamStage = zdss_init;
2975  someMoreWork = 0;
2976  break;
2977  }
2978  if ((size_t)(iend-ip) >= neededInSize) { /* decode directly from src */
2979  int const isSkipFrame = ZSTD_isSkipFrame(zds);
2980  size_t const decodedSize = ZSTD_decompressContinue(zds,
2981  zds->outBuff + zds->outStart, (isSkipFrame ? 0 : zds->outBuffSize - zds->outStart),
2982  ip, neededInSize);
2983  if (ZSTD_isError(decodedSize)) return decodedSize;
2984  ip += neededInSize;
2985  if (!decodedSize && !isSkipFrame) break; /* this was just a header */
2986  zds->outEnd = zds->outStart + decodedSize;
2987  zds->streamStage = zdss_flush;
2988  break;
2989  } }
2990  if (ip==iend) { someMoreWork = 0; break; } /* no more input */
2991  zds->streamStage = zdss_load;
2992  /* fall-through */
2993 
2994  case zdss_load:
2995  { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds);
2996  size_t const toLoad = neededInSize - zds->inPos;
2997  int const isSkipFrame = ZSTD_isSkipFrame(zds);
2998  size_t loadedSize;
2999  if (isSkipFrame) {
3000  loadedSize = MIN(toLoad, (size_t)(iend-ip));
3001  } else {
3002  if (toLoad > zds->inBuffSize - zds->inPos) return ERROR(corruption_detected); /* should never happen */
3003  loadedSize = ZSTD_limitCopy(zds->inBuff + zds->inPos, toLoad, ip, iend-ip);
3004  }
3005  ip += loadedSize;
3006  zds->inPos += loadedSize;
3007  if (loadedSize < toLoad) { someMoreWork = 0; break; } /* not enough input, wait for more */
3008 
3009  /* decode loaded input */
3010  { size_t const decodedSize = ZSTD_decompressContinue(zds,
3011  zds->outBuff + zds->outStart, zds->outBuffSize - zds->outStart,
3012  zds->inBuff, neededInSize);
3013  if (ZSTD_isError(decodedSize)) return decodedSize;
3014  zds->inPos = 0; /* input is consumed */
3015  if (!decodedSize && !isSkipFrame) { zds->streamStage = zdss_read; break; } /* this was just a header */
3016  zds->outEnd = zds->outStart + decodedSize;
3017  } }
3018  zds->streamStage = zdss_flush;
3019  /* fall-through */
3020 
3021  case zdss_flush:
3022  { size_t const toFlushSize = zds->outEnd - zds->outStart;
3023  size_t const flushedSize = ZSTD_limitCopy(op, oend-op, zds->outBuff + zds->outStart, toFlushSize);
3024  op += flushedSize;
3025  zds->outStart += flushedSize;
3026  if (flushedSize == toFlushSize) { /* flush completed */
3027  zds->streamStage = zdss_read;
3028  if ( (zds->outBuffSize < zds->fParams.frameContentSize)
3029  && (zds->outStart + zds->fParams.blockSizeMax > zds->outBuffSize) ) {
3030  DEBUGLOG(5, "restart filling outBuff from beginning (left:%i, needed:%u)",
3031  (int)(zds->outBuffSize - zds->outStart),
3032  (U32)zds->fParams.blockSizeMax);
3033  zds->outStart = zds->outEnd = 0;
3034  }
3035  break;
3036  } }
3037  /* cannot complete flush */
3038  someMoreWork = 0;
3039  break;
3040 
3041  default: return ERROR(GENERIC); /* impossible */
3042  } }
3043 
3044  /* result */
3045  input->pos = (size_t)(ip - (const char*)(input->src));
3046  output->pos = (size_t)(op - (char*)(output->dst));
3047  if ((ip==istart) && (op==ostart)) { /* no forward progress */
3048  zds->noForwardProgress ++;
3050  if (op==oend) return ERROR(dstSize_tooSmall);
3051  if (ip==iend) return ERROR(srcSize_wrong);
3052  assert(0);
3053  }
3054  } else {
3055  zds->noForwardProgress = 0;
3056  }
3057  { size_t nextSrcSizeHint = ZSTD_nextSrcSizeToDecompress(zds);
3058  if (!nextSrcSizeHint) { /* frame fully decoded */
3059  if (zds->outEnd == zds->outStart) { /* output fully flushed */
3060  if (zds->hostageByte) {
3061  if (input->pos >= input->size) {
3062  /* can't release hostage (not present) */
3063  zds->streamStage = zdss_read;
3064  return 1;
3065  }
3066  input->pos++; /* release hostage */
3067  } /* zds->hostageByte */
3068  return 0;
3069  } /* zds->outEnd == zds->outStart */
3070  if (!zds->hostageByte) { /* output not fully flushed; keep last byte as hostage; will be released when all output is flushed */
3071  input->pos--; /* note : pos > 0, otherwise, impossible to finish reading last block */
3072  zds->hostageByte=1;
3073  }
3074  return 1;
3075  } /* nextSrcSizeHint==0 */
3076  nextSrcSizeHint += ZSTD_blockHeaderSize * (ZSTD_nextInputType(zds) == ZSTDnit_block); /* preload header of next block */
3077  assert(zds->inPos <= nextSrcSizeHint);
3078  nextSrcSizeHint -= zds->inPos; /* part already loaded*/
3079  return nextSrcSizeHint;
3080  }
3081 }
#define ZSTD_NO_FORWARD_PROGRESS_MAX
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
const void * dictContent
ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx *dctx)
ZSTD_frameHeader fParams
#define ERROR(name)
Definition: error_private.h:53
ZSTD_dStreamStage streamStage
void ZSTD_free(void *ptr, ZSTD_customMem customMem)
Definition: zstd_common.c:68
static int ZSTD_isSkipFrame(ZSTD_DCtx *dctx)
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
Definition: mem.h:273
#define U(x)
Definition: wordpad.c:44
#define ZSTD_WINDOWLOG_ABSOLUTEMIN
Definition: zstd_internal.h:77
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
ZSTD_format_e format
T MIN(T a, T b)
Definition: polytest.cpp:79
#define DEBUGLOG(l,...)
Definition: debug.h:115
size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx *dctx)
static const size_t ZSTD_blockHeaderSize
Definition: zstd_internal.h:85
void * legacyContext
size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader *zfhPtr, const void *src, size_t srcSize, ZSTD_format_e format)
size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
smooth NULL
Definition: ftsmooth.c:416
size_t ZSTD_resetDStream(ZSTD_DStream *dctx)
ZSTD_customMem customMem
#define CHECK_F(f)
Definition: fse_compress.c:661
BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX]
MEM_STATIC size_t ZSTD_limitCopy(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
const ZSTD_DDict * ddict
static size_t ZSTD_decodeFrameHeader(ZSTD_DCtx *dctx, const void *src, size_t headerSize)
__kernel_size_t size_t
Definition: linux.h:237
Definition: dhcpd.h:61
if(!(yy_init))
Definition: macro.lex.yy.c:714
size_t ZSTD_decompress_usingDDict(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_DDict *ddict)
ZSTD_dStage stage
size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
void * ZSTD_malloc(size_t size, ZSTD_customMem customMem)
Definition: zstd_common.c:54
T MAX(T a, T b)
Definition: polytest.cpp:85
U32 previousLegacyVersion
#define ZSTD_isError
size_t ZSTD_decompressContinue(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
DWORD hint
Definition: vfdcmd.c:88
GLenum GLenum GLenum input
Definition: glext.h:9031
unsigned long long U64
Definition: mem.h:81
size_t outBuffSize
#define ZSTD_FRAMEIDSIZE
Definition: zstd_internal.h:82
size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize)
UINT op
Definition: effect.c:223
size_t maxWindowSize
BOOL expected
Definition: store.c:2063

Referenced by zstd_decompress(), and ZSTD_decompress_generic().

◆ ZSTD_DStreamInSize()

size_t ZSTD_DStreamInSize ( void  )

recommended size for input buffer

Definition at line 2656 of file zstd_decompress.c.

2656 { return ZSTD_BLOCKSIZE_MAX + ZSTD_blockHeaderSize; }
static const size_t ZSTD_blockHeaderSize
Definition: zstd_internal.h:85

◆ ZSTD_DStreamOutSize()

size_t ZSTD_DStreamOutSize ( void  )

recommended size for output buffer. Guarantee to successfully flush at least one complete block in all circumstances.

Definition at line 2657 of file zstd_decompress.c.

2657 { return ZSTD_BLOCKSIZE_MAX; }

◆ ZSTD_estimateDCtxSize()

size_t ZSTD_estimateDCtxSize ( void  )

Definition at line 189 of file zstd_decompress.c.

189 { return sizeof(ZSTD_DCtx); }
struct ZSTD_DCtx_s ZSTD_DCtx
Definition: zstd.h:182

Referenced by ZSTD_estimateDStreamSize().

◆ ZSTD_estimateDDictSize()

size_t ZSTD_estimateDDictSize ( size_t  dictSize,
ZSTD_dictLoadMethod_e  dictLoadMethod 
)

ZSTD_estimateDDictSize() : Estimate amount of memory that will be needed to create a dictionary for decompression. Note : dictionary created by reference using ZSTD_dlm_byRef are smaller

Definition at line 2559 of file zstd_decompress.c.

2560 {
2561  return sizeof(ZSTD_DDict) + (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize);
2562 }
struct ZSTD_DDict_s ZSTD_DDict
Definition: zstd.h:248

◆ ZSTD_estimateDStreamSize()

size_t ZSTD_estimateDStreamSize ( size_t  windowSize)

Definition at line 2792 of file zstd_decompress.c.

2793 {
2794  size_t const blockSize = MIN(windowSize, ZSTD_BLOCKSIZE_MAX);
2795  size_t const inBuffSize = blockSize; /* no block can be larger */
2796  size_t const outBuffSize = ZSTD_decodingBufferSize_min(windowSize, ZSTD_CONTENTSIZE_UNKNOWN);
2797  return ZSTD_estimateDCtxSize() + inBuffSize + outBuffSize;
2798 }
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
T MIN(T a, T b)
Definition: polytest.cpp:79
size_t ZSTD_estimateDCtxSize(void)
size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize)

Referenced by ZSTD_estimateDStreamSize_fromFrame().

◆ ZSTD_estimateDStreamSize_fromFrame()

size_t ZSTD_estimateDStreamSize_fromFrame ( const void src,
size_t  srcSize 
)

Definition at line 2800 of file zstd_decompress.c.

2801 {
2802  U32 const windowSizeMax = 1U << ZSTD_WINDOWLOG_MAX; /* note : should be user-selectable */
2803  ZSTD_frameHeader zfh;
2804  size_t const err = ZSTD_getFrameHeader(&zfh, src, srcSize);
2805  if (ZSTD_isError(err)) return err;
2806  if (err>0) return ERROR(srcSize_wrong);
2807  if (zfh.windowSize > windowSizeMax)
2808  return ERROR(frameParameter_windowTooLarge);
2809  return ZSTD_estimateDStreamSize((size_t)zfh.windowSize);
2810 }
#define ERROR(name)
Definition: error_private.h:53
#define U(x)
Definition: wordpad.c:44
unsigned int U32
Definition: mem.h:77
size_t ZSTD_estimateDStreamSize(size_t windowSize)
size_t ZSTD_getFrameHeader(ZSTD_frameHeader *zfhPtr, const void *src, size_t srcSize)
GLenum src
Definition: glext.h:6340
#define err(...)
#define ZSTD_isError

◆ ZSTD_execSequence()

HINT_INLINE size_t ZSTD_execSequence ( BYTE op,
BYTE *const  oend,
seq_t  sequence,
const BYTE **  litPtr,
const BYTE *const  litLimit,
const BYTE *const  prefixStart,
const BYTE *const  virtualStart,
const BYTE *const  dictEnd 
)

Definition at line 1133 of file zstd_decompress.c.

1137 {
1138  BYTE* const oLitEnd = op + sequence.litLength;
1139  size_t const sequenceLength = sequence.litLength + sequence.matchLength;
1140  BYTE* const oMatchEnd = op + sequenceLength; /* risk : address space overflow (32-bits) */
1141  BYTE* const oend_w = oend - WILDCOPY_OVERLENGTH;
1142  const BYTE* const iLitEnd = *litPtr + sequence.litLength;
1143  const BYTE* match = oLitEnd - sequence.offset;
1144 
1145  /* check */
1146  if (oMatchEnd>oend) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of WILDCOPY_OVERLENGTH from oend */
1147  if (iLitEnd > litLimit) return ERROR(corruption_detected); /* over-read beyond lit buffer */
1148  if (oLitEnd>oend_w) return ZSTD_execSequenceLast7(op, oend, sequence, litPtr, litLimit, prefixStart, virtualStart, dictEnd);
1149 
1150  /* copy Literals */
1151  ZSTD_copy8(op, *litPtr);
1152  if (sequence.litLength > 8)
1153  ZSTD_wildcopy(op+8, (*litPtr)+8, sequence.litLength - 8); /* note : since oLitEnd <= oend-WILDCOPY_OVERLENGTH, no risk of overwrite beyond oend */
1154  op = oLitEnd;
1155  *litPtr = iLitEnd; /* update for next sequence */
1156 
1157  /* copy Match */
1158  if (sequence.offset > (size_t)(oLitEnd - prefixStart)) {
1159  /* offset beyond prefix -> go into extDict */
1160  if (sequence.offset > (size_t)(oLitEnd - virtualStart))
1161  return ERROR(corruption_detected);
1162  match = dictEnd + (match - prefixStart);
1163  if (match + sequence.matchLength <= dictEnd) {
1164  memmove(oLitEnd, match, sequence.matchLength);
1165  return sequenceLength;
1166  }
1167  /* span extDict & currentPrefixSegment */
1168  { size_t const length1 = dictEnd - match;
1169  memmove(oLitEnd, match, length1);
1170  op = oLitEnd + length1;
1171  sequence.matchLength -= length1;
1172  match = prefixStart;
1173  if (op > oend_w || sequence.matchLength < MINMATCH) {
1174  U32 i;
1175  for (i = 0; i < sequence.matchLength; ++i) op[i] = match[i];
1176  return sequenceLength;
1177  }
1178  } }
1179  /* Requirement: op <= oend_w && sequence.matchLength >= MINMATCH */
1180 
1181  /* match within prefix */
1182  if (sequence.offset < 8) {
1183  /* close range match, overlap */
1184  static const U32 dec32table[] = { 0, 1, 2, 1, 4, 4, 4, 4 }; /* added */
1185  static const int dec64table[] = { 8, 8, 8, 7, 8, 9,10,11 }; /* subtracted */
1186  int const sub2 = dec64table[sequence.offset];
1187  op[0] = match[0];
1188  op[1] = match[1];
1189  op[2] = match[2];
1190  op[3] = match[3];
1191  match += dec32table[sequence.offset];
1192  ZSTD_copy4(op+4, match);
1193  match -= sub2;
1194  } else {
1195  ZSTD_copy8(op, match);
1196  }
1197  op += 8; match += 8;
1198 
1199  if (oMatchEnd > oend-(16-MINMATCH)) {
1200  if (op < oend_w) {
1201  ZSTD_wildcopy(op, match, oend_w - op);
1202  match += oend_w - op;
1203  op = oend_w;
1204  }
1205  while (op < oMatchEnd) *op++ = *match++;
1206  } else {
1207  ZSTD_wildcopy(op, match, (ptrdiff_t)sequence.matchLength-8); /* works even if matchLength < 8 */
1208  }
1209  return sequenceLength;
1210 }
#define WILDCOPY_OVERLENGTH
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static void ZSTD_copy8(void *dst, const void *src)
Definition: match.c:28
#define ERROR(name)
Definition: error_private.h:53
unsigned int U32
Definition: mem.h:77
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
FORCE_NOINLINE size_t ZSTD_execSequenceLast7(BYTE *op, BYTE *const oend, seq_t sequence, const BYTE **litPtr, const BYTE *const litLimit, const BYTE *const base, const BYTE *const vBase, const BYTE *const dictEnd)
static void ZSTD_copy4(void *dst, const void *src)
MEM_STATIC void ZSTD_wildcopy(void *dst, const void *src, ptrdiff_t length)
struct match match
Definition: match.c:33
static struct message * sequence
Definition: subclass.c:48
unsigned char BYTE
Definition: mem.h:68
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
#define MINMATCH
Definition: zstd_internal.h:96
UINT op
Definition: effect.c:223

Referenced by ZSTD_decompressSequences_body().

◆ ZSTD_execSequenceLast7()

FORCE_NOINLINE size_t ZSTD_execSequenceLast7 ( BYTE op,
BYTE *const  oend,
seq_t  sequence,
const BYTE **  litPtr,
const BYTE *const  litLimit,
const BYTE *const  base,
const BYTE *const  vBase,
const BYTE *const  dictEnd 
)

Definition at line 1086 of file zstd_decompress.c.

1090 {
1091  BYTE* const oLitEnd = op + sequence.litLength;
1092  size_t const sequenceLength = sequence.litLength + sequence.matchLength;
1093  BYTE* const oMatchEnd = op + sequenceLength; /* risk : address space overflow (32-bits) */
1094  BYTE* const oend_w = oend - WILDCOPY_OVERLENGTH;
1095  const BYTE* const iLitEnd = *litPtr + sequence.litLength;
1096  const BYTE* match = oLitEnd - sequence.offset;
1097 
1098  /* check */
1099  if (oMatchEnd>oend) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of WILDCOPY_OVERLENGTH from oend */
1100  if (iLitEnd > litLimit) return ERROR(corruption_detected); /* over-read beyond lit buffer */
1101  if (oLitEnd <= oend_w) return ERROR(GENERIC); /* Precondition */
1102 
1103  /* copy literals */
1104  if (op < oend_w) {
1105  ZSTD_wildcopy(op, *litPtr, oend_w - op);
1106  *litPtr += oend_w - op;
1107  op = oend_w;
1108  }
1109  while (op < oLitEnd) *op++ = *(*litPtr)++;
1110 
1111  /* copy Match */
1112  if (sequence.offset > (size_t)(oLitEnd - base)) {
1113  /* offset beyond prefix */
1114  if (sequence.offset > (size_t)(oLitEnd - vBase)) return ERROR(corruption_detected);
1115  match = dictEnd - (base-match);
1116  if (match + sequence.matchLength <= dictEnd) {
1117  memmove(oLitEnd, match, sequence.matchLength);
1118  return sequenceLength;
1119  }
1120  /* span extDict & currentPrefixSegment */
1121  { size_t const length1 = dictEnd - match;
1122  memmove(oLitEnd, match, length1);
1123  op = oLitEnd + length1;
1124  sequence.matchLength -= length1;
1125  match = base;
1126  } }
1127  while (op < oMatchEnd) *op++ = *match++;
1128  return sequenceLength;
1129 }
#define WILDCOPY_OVERLENGTH
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
Definition: match.c:28
#define ERROR(name)
Definition: error_private.h:53
GLuint base
Definition: 3dtext.c:35
MEM_STATIC void ZSTD_wildcopy(void *dst, const void *src, ptrdiff_t length)
struct match match
Definition: match.c:33
static struct message * sequence
Definition: subclass.c:48
unsigned char BYTE
Definition: mem.h:68
UINT op
Definition: effect.c:223

Referenced by ZSTD_execSequence(), and ZSTD_execSequenceLong().

◆ ZSTD_execSequenceLong()

HINT_INLINE size_t ZSTD_execSequenceLong ( BYTE op,
BYTE *const  oend,
seq_t  sequence,
const BYTE **  litPtr,
const BYTE *const  litLimit,
const BYTE *const  prefixStart,
const BYTE *const  dictStart,
const BYTE *const  dictEnd 
)

Definition at line 1214 of file zstd_decompress.c.

1218 {
1219  BYTE* const oLitEnd = op + sequence.litLength;
1220  size_t const sequenceLength = sequence.litLength + sequence.matchLength;
1221  BYTE* const oMatchEnd = op + sequenceLength; /* risk : address space overflow (32-bits) */
1222  BYTE* const oend_w = oend - WILDCOPY_OVERLENGTH;
1223  const BYTE* const iLitEnd = *litPtr + sequence.litLength;
1224  const BYTE* match = sequence.match;
1225 
1226  /* check */
1227  if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of WILDCOPY_OVERLENGTH from oend */
1228  if (iLitEnd > litLimit) return ERROR(corruption_detected); /* over-read beyond lit buffer */
1229  if (oLitEnd > oend_w) return ZSTD_execSequenceLast7(op, oend, sequence, litPtr, litLimit, prefixStart, dictStart, dictEnd);
1230 
1231  /* copy Literals */
1232  ZSTD_copy8(op, *litPtr); /* note : op <= oLitEnd <= oend_w == oend - 8 */
1233  if (sequence.litLength > 8)
1234