NeoMutt  2025-12-11-1009-ga75d9e
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, size_t *dlen)
 Decompress header cache data - Implements ComprOps::decompress() -.
static void * compr_zlib_decompress (ComprHandle *handle, const char *cbuf, size_t clen, size_t *dlen)
 Decompress header cache data - Implements ComprOps::decompress() -.
static void * compr_zstd_decompress (ComprHandle *handle, const char *cbuf, size_t clen, size_t *dlen)
 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
[out]dlenLength of the decompressed output 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()

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

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

Definition at line 138 of file lz4.c.

140{
141 if (!handle)
142 return NULL;
143
144 // Decloak an opaque pointer
145 struct Lz4ComprData *cdata = handle;
146
147 /* first 4 bytes store the size */
148 const unsigned char *cs = (const unsigned char *) cbuf;
149 if (clen < 4)
150 return NULL;
151 if ((clen - 4) > INT_MAX)
152 return NULL;
153 size_t ulen = cs[0] + (cs[1] << 8) + (cs[2] << 16) + ((size_t) cs[3] << 24);
154 if (ulen > INT_MAX)
155 return NULL; // LCOV_EXCL_LINE
156 if (ulen == 0)
157 {
158 if (dlen)
159 *dlen = 0;
160 return (void *) cbuf;
161 }
162
163 mutt_mem_realloc(&cdata->buf, ulen);
164 void *ubuf = cdata->buf;
165 const char *data = cbuf;
166 int rc = LZ4_decompress_safe(data + 4, ubuf, clen - 4, ulen);
167 if (rc < 0)
168 return NULL;
169
170 if (dlen)
171 *dlen = rc;
172
173 return ubuf;
174}
void mutt_mem_realloc(void *pptr, size_t size)
Resize a block of memory on the heap.
Definition memory.c:149
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()

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

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

Definition at line 136 of file zlib.c.

138{
139 if (!handle)
140 return NULL;
141
142 // Decloak an opaque pointer
143 struct ZlibComprData *cdata = handle;
144
145 /* first 4 bytes store the size */
146 const unsigned char *cs = (const unsigned char *) cbuf;
147 if (clen < 4)
148 return NULL;
149 uLong ulen = cs[0] + (cs[1] << 8) + (cs[2] << 16) + ((uLong) cs[3] << 24);
150 if (ulen == 0)
151 return NULL;
152
153 mutt_mem_realloc(&cdata->buf, ulen);
154 Bytef *ubuf = cdata->buf;
155 cs = (const unsigned char *) cbuf;
156 int rc = uncompress(ubuf, &ulen, cs + 4, clen - 4);
157 if (rc != Z_OK)
158 return NULL;
159
160 if (dlen)
161 *dlen = ulen;
162
163 return ubuf;
164}
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()

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

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

Definition at line 139 of file zstd.c.

141{
142 if (!handle)
143 return NULL;
144
145 // Decloak an opaque pointer
146 struct ZstdComprData *cdata = handle;
147
148 unsigned long long len = ZSTD_getFrameContentSize(cbuf, clen);
149 if (len == ZSTD_CONTENTSIZE_UNKNOWN)
150 return NULL; // LCOV_EXCL_LINE
151 else if (len == ZSTD_CONTENTSIZE_ERROR)
152 return NULL;
153 else if (len == 0)
154 return NULL; // LCOV_EXCL_LINE
155 mutt_mem_realloc(&cdata->buf, len);
156
157 size_t rc = ZSTD_decompressDCtx(cdata->dctx, cdata->buf, len, cbuf, clen);
158 if (ZSTD_isError(rc))
159 return NULL; // LCOV_EXCL_LINE
160
161 if (dlen)
162 *dlen = rc;
163
164 return cdata->buf;
165}
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: