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

Function ZSTD_decodeLiteralsBlock

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

! ZSTD_decodeLiteralsBlock() : * @return : nb of bytes read from src (< srcSize ) * note : symbol not declared but exposed for fullbench */

Source from the content-addressed store, hash-verified

26470 * @return : nb of bytes read from src (< srcSize )
26471 * note : symbol not declared but exposed for fullbench */
26472size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx,
26473 const void* src, size_t srcSize) /* note : srcSize < BLOCKSIZE */
26474{
26475 DEBUGLOG(5, "ZSTD_decodeLiteralsBlock");
26476 RETURN_ERROR_IF(srcSize < MIN_CBLOCK_SIZE, corruption_detected, "");
26477
26478 { const BYTE* const istart = (const BYTE*) src;
26479 symbolEncodingType_e const litEncType = (symbolEncodingType_e)(istart[0] & 3);
26480
26481 switch(litEncType)
26482 {
26483 case set_repeat:
26484 DEBUGLOG(5, "set_repeat flag : re-using stats from previous compressed literals block");
26485 RETURN_ERROR_IF(dctx->litEntropy==0, dictionary_corrupted, "");
26486 /* fall-through */
26487
26488 case set_compressed:
26489 RETURN_ERROR_IF(srcSize < 5, corruption_detected, "srcSize >= MIN_CBLOCK_SIZE == 3; here we need up to 5 for case 3");
26490 { size_t lhSize, litSize, litCSize;
26491 U32 singleStream=0;
26492 U32 const lhlCode = (istart[0] >> 2) & 3;
26493 U32 const lhc = MEM_readLE32(istart);
26494 size_t hufSuccess;
26495 switch(lhlCode)
26496 {
26497 case 0: case 1: default: /* note : default is impossible, since lhlCode into [0..3] */
26498 /* 2 - 2 - 10 - 10 */
26499 singleStream = !lhlCode;
26500 lhSize = 3;
26501 litSize = (lhc >> 4) & 0x3FF;
26502 litCSize = (lhc >> 14) & 0x3FF;
26503 break;
26504 case 2:
26505 /* 2 - 2 - 14 - 14 */
26506 lhSize = 4;
26507 litSize = (lhc >> 4) & 0x3FFF;
26508 litCSize = lhc >> 18;
26509 break;
26510 case 3:
26511 /* 2 - 2 - 18 - 18 */
26512 lhSize = 5;
26513 litSize = (lhc >> 4) & 0x3FFFF;
26514 litCSize = (lhc >> 22) + ((size_t)istart[4] << 10);
26515 break;
26516 }
26517 RETURN_ERROR_IF(litSize > ZSTD_BLOCKSIZE_MAX, corruption_detected, "");
26518 RETURN_ERROR_IF(litCSize + lhSize > srcSize, corruption_detected, "");
26519
26520 /* prefetch huffman table if cold */
26521 if (dctx->ddictIsCold && (litSize > 768 /* heuristic */)) {
26522 PREFETCH_AREA(dctx->HUFptr, sizeof(dctx->entropy.hufTable));
26523 }
26524
26525 if (litEncType==set_repeat) {
26526 if (singleStream) {
26527 hufSuccess = HUF_decompress1X_usingDTable_bmi2(
26528 dctx->litBuffer, litSize, istart+lhSize, litCSize,
26529 dctx->HUFptr, dctx->bmi2);

Callers 1

Calls 11

memsetFunction · 0.85
MEM_readLE32Function · 0.70
HUF_isErrorFunction · 0.70
MEM_readLE16Function · 0.70
MEM_readLE24Function · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected