MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / zip_extract_entry

Function zip_extract_entry

src/cli/cli.c:6287–6331  ·  view source on GitHub ↗

Decompress a single zip entry (stored or deflated). Returns malloc'd buffer * or NULL on failure. *out_len receives the decompressed size. */

Source from the content-addressed store, hash-verified

6285/* Decompress a single zip entry (stored or deflated). Returns malloc'd buffer
6286 * or NULL on failure. *out_len receives the decompressed size. */
6287static unsigned char *zip_extract_entry(const unsigned char *file_data, uint16_t method,
6288 size_t comp_size, size_t uncomp_size, int *out_len) {
6289 if (method == ZIP_STORED) {
6290 if (comp_size > ZIP_MAX_UNCOMP) {
6291 return NULL;
6292 }
6293 unsigned char *out = malloc(comp_size);
6294 if (!out) {
6295 return NULL;
6296 }
6297 memcpy(out, file_data, comp_size);
6298 *out_len = (int)comp_size;
6299 return out;
6300 }
6301 if (method == ZIP_DEFLATE) {
6302 if (uncomp_size > ZIP_MAX_UNCOMP) {
6303 return NULL;
6304 }
6305 if (comp_size > UINT_MAX || uncomp_size > UINT_MAX) {
6306 return NULL;
6307 }
6308 unsigned char *out = malloc(uncomp_size);
6309 if (!out) {
6310 return NULL;
6311 }
6312 z_stream strm = {0};
6313 strm.next_in = (unsigned char *)file_data;
6314 strm.avail_in = (uInt)comp_size;
6315 strm.next_out = out;
6316 strm.avail_out = (uInt)uncomp_size;
6317 if (inflateInit2(&strm, -MAX_WBITS) != Z_OK) {
6318 free(out);
6319 return NULL;
6320 }
6321 int ret = inflate(&strm, Z_FINISH);
6322 inflateEnd(&strm);
6323 if (ret != Z_STREAM_END) {
6324 free(out);
6325 return NULL;
6326 }
6327 *out_len = (int)strm.total_out;
6328 return out;
6329 }
6330 return NULL; /* unknown method */
6331}
6332
6333unsigned char *cbm_extract_binary_from_zip(const unsigned char *data, int data_len, int *out_len) {
6334 if (!data || data_len <= 0 || !out_len) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected