NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
decompress()

Decompress header cache data. More...

+ Collaboration diagram for decompress():

Functions

static void * compr_lz4_decompress (ComprHandle *handle, const char *cbuf, size_t clen)
 Decompress header cache data - Implements ComprOps::decompress() -.
 
static void * compr_zlib_decompress (ComprHandle *handle, const char *cbuf, size_t clen)
 Decompress header cache data - Implements ComprOps::decompress() -.
 
static void * compr_zstd_decompress (ComprHandle *handle, const char *cbuf, size_t clen)
 Decompress header cache data - Implements ComprOps::decompress() -.
 

Detailed Description

Decompress header cache data.

Parameters
[in]handleCompression handle
[in]cbufData to be decompressed
[in]clenLength of the compressed input data
Return values
ptrSuccess, pointer to decompressed data
NULLOtherwise
Note
This function returns a pointer to data, which will be freed by the close() function.

Function Documentation

◆ compr_lz4_decompress()

static void * compr_lz4_decompress ( ComprHandle * handle,
const char * cbuf,
size_t clen )
static

Decompress header cache data - Implements ComprOps::decompress() -.

Definition at line 138 of file lz4.c.

139{
140 if (!handle)
141 return NULL;
142
143 // Decloak an opaque pointer
144 struct Lz4ComprData *cdata = handle;
145
146 /* first 4 bytes store the size */
147 const unsigned char *cs = (const unsigned char *) cbuf;
148 if (clen < 4)
149 return NULL;
150 if ((clen - 4) > INT_MAX)
151 return NULL;
152 size_t ulen = cs[0] + (cs[1] << 8) + (cs[2] << 16) + ((size_t) cs[3] << 24);
153 if (ulen > INT_MAX)
154 return NULL; // LCOV_EXCL_LINE
155 if (ulen == 0)
156 return (void *) cbuf;
157
158 mutt_mem_realloc(&cdata->buf, ulen);
159 void *ubuf = cdata->buf;
160 const char *data = cbuf;
161 int rc = LZ4_decompress_safe(data + 4, ubuf, clen - 4, ulen);
162 if (rc < 0)
163 return NULL;
164
165 return ubuf;
166}
void mutt_mem_realloc(void *pptr, size_t size)
Resize a block of memory on the heap.
Definition memory.c:146
Private Lz4 Compression Data.
Definition lz4.c:47
void * buf
Temporary buffer.
Definition lz4.c:48
+ Here is the call graph for this function:

◆ compr_zlib_decompress()

static void * compr_zlib_decompress ( ComprHandle * handle,
const char * cbuf,
size_t clen )
static

Decompress header cache data - Implements ComprOps::decompress() -.

Definition at line 136 of file zlib.c.

137{
138 if (!handle)
139 return NULL;
140
141 // Decloak an opaque pointer
142 struct ZlibComprData *cdata = handle;
143
144 /* first 4 bytes store the size */
145 const unsigned char *cs = (const unsigned char *) cbuf;
146 if (clen < 4)
147 return NULL;
148 uLong ulen = cs[0] + (cs[1] << 8) + (cs[2] << 16) + ((uLong) cs[3] << 24);
149 if (ulen == 0)
150 return NULL;
151
152 mutt_mem_realloc(&cdata->buf, ulen);
153 Bytef *ubuf = cdata->buf;
154 cs = (const unsigned char *) cbuf;
155 int rc = uncompress(ubuf, &ulen, cs + 4, clen - 4);
156 if (rc != Z_OK)
157 return NULL;
158
159 return ubuf;
160}
Private Zlib Compression Data.
Definition zlib.c:48
void * buf
Temporary buffer.
Definition zlib.c:49
+ Here is the call graph for this function:

◆ compr_zstd_decompress()

static void * compr_zstd_decompress ( ComprHandle * handle,
const char * cbuf,
size_t clen )
static

Decompress header cache data - Implements ComprOps::decompress() -.

Definition at line 139 of file zstd.c.

140{
141 if (!handle)
142 return NULL;
143
144 // Decloak an opaque pointer
145 struct ZstdComprData *cdata = handle;
146
147 unsigned long long len = ZSTD_getFrameContentSize(cbuf, clen);
148 if (len == ZSTD_CONTENTSIZE_UNKNOWN)
149 return NULL; // LCOV_EXCL_LINE
150 else if (len == ZSTD_CONTENTSIZE_ERROR)
151 return NULL;
152 else if (len == 0)
153 return NULL; // LCOV_EXCL_LINE
154 mutt_mem_realloc(&cdata->buf, len);
155
156 size_t rc = ZSTD_decompressDCtx(cdata->dctx, cdata->buf, len, cbuf, clen);
157 if (ZSTD_isError(rc))
158 return NULL; // LCOV_EXCL_LINE
159
160 return cdata->buf;
161}
Private Zstandard Compression Data.
Definition zstd.c:46
ZSTD_DCtx * dctx
Decompression context.
Definition zstd.c:51
void * buf
Temporary buffer.
Definition zstd.c:47
+ Here is the call graph for this function: