MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ZSTD_decompressStream

Function ZSTD_decompressStream

freebsd/contrib/openzfs/module/zstd/lib/zstd.c:26094–26377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26092}
26093
26094size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input)
26095{
26096 const char* const src = (const char*)input->src;
26097 const char* const istart = input->pos != 0 ? src + input->pos : src;
26098 const char* const iend = input->size != 0 ? src + input->size : src;
26099 const char* ip = istart;
26100 char* const dst = (char*)output->dst;
26101 char* const ostart = output->pos != 0 ? dst + output->pos : dst;
26102 char* const oend = output->size != 0 ? dst + output->size : dst;
26103 char* op = ostart;
26104 U32 someMoreWork = 1;
26105
26106 DEBUGLOG(5, "ZSTD_decompressStream");
26107 RETURN_ERROR_IF(
26108 input->pos > input->size,
26109 srcSize_wrong,
26110 "forbidden. in: pos: %u vs size: %u",
26111 (U32)input->pos, (U32)input->size);
26112 RETURN_ERROR_IF(
26113 output->pos > output->size,
26114 dstSize_tooSmall,
26115 "forbidden. out: pos: %u vs size: %u",
26116 (U32)output->pos, (U32)output->size);
26117 DEBUGLOG(5, "input size : %u", (U32)(input->size - input->pos));
26118 FORWARD_IF_ERROR(ZSTD_checkOutBuffer(zds, output), "");
26119
26120 while (someMoreWork) {
26121 switch(zds->streamStage)
26122 {
26123 case zdss_init :
26124 DEBUGLOG(5, "stage zdss_init => transparent reset ");
26125 zds->streamStage = zdss_loadHeader;
26126 zds->lhSize = zds->inPos = zds->outStart = zds->outEnd = 0;
26127 zds->legacyVersion = 0;
26128 zds->hostageByte = 0;
26129 zds->expectedOutBuffer = *output;
26130 /* fall-through */
26131
26132 case zdss_loadHeader :
26133 DEBUGLOG(5, "stage zdss_loadHeader (srcSize : %u)", (U32)(iend - ip));
26134#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
26135 if (zds->legacyVersion) {
26136 RETURN_ERROR_IF(zds->staticSize, memory_allocation,
26137 "legacy support is incompatible with static dctx");
26138 { size_t const hint = ZSTD_decompressLegacyStream(zds->legacyContext, zds->legacyVersion, output, input);
26139 if (hint==0) zds->streamStage = zdss_init;
26140 return hint;
26141 } }
26142#endif
26143 { size_t const hSize = ZSTD_getFrameHeader_advanced(&zds->fParams, zds->headerBuffer, zds->lhSize, zds->format);
26144 DEBUGLOG(5, "header size : %u", (U32)hSize);
26145 if (ZSTD_isError(hSize)) {
26146#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
26147 U32 const legacyVersion = ZSTD_isLegacy(istart, iend-istart);
26148 if (legacyVersion) {
26149 ZSTD_DDict const* const ddict = ZSTD_getDDict(zds);
26150 const void* const dict = ddict ? ZSTD_DDict_dictContent(ddict) : NULL;
26151 size_t const dictSize = ddict ? ZSTD_DDict_dictSize(ddict) : 0;

Callers 1

Calls 15

ZSTD_freeFunction · 0.85
ZSTD_mallocFunction · 0.85
ZSTD_checkOutBufferFunction · 0.70
ZSTD_isErrorFunction · 0.70
ZSTD_isLegacyFunction · 0.70
ZSTD_getDDictFunction · 0.70
ZSTD_DDict_dictContentFunction · 0.70
ZSTD_DDict_dictSizeFunction · 0.70
ZSTD_initLegacyStreamFunction · 0.70

Tested by

no test coverage detected