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

Function zip_extract_entry

src/cli/cli.c:7218–7262  ·  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

7216/* Decompress a single zip entry (stored or deflated). Returns malloc'd buffer
7217 * or NULL on failure. *out_len receives the decompressed size. */
7218static unsigned char *zip_extract_entry(const unsigned char *file_data, uint16_t method,
7219 size_t comp_size, size_t uncomp_size, int *out_len) {
7220 if (method == ZIP_STORED) {
7221 if (comp_size > ZIP_MAX_UNCOMP) {
7222 return NULL;
7223 }
7224 unsigned char *out = malloc(comp_size);
7225 if (!out) {
7226 return NULL;
7227 }
7228 memcpy(out, file_data, comp_size);
7229 *out_len = (int)comp_size;
7230 return out;
7231 }
7232 if (method == ZIP_DEFLATE) {
7233 if (uncomp_size > ZIP_MAX_UNCOMP) {
7234 return NULL;
7235 }
7236 if (comp_size > UINT_MAX || uncomp_size > UINT_MAX) {
7237 return NULL;
7238 }
7239 unsigned char *out = malloc(uncomp_size);
7240 if (!out) {
7241 return NULL;
7242 }
7243 z_stream strm = {0};
7244 strm.next_in = (unsigned char *)file_data;
7245 strm.avail_in = (uInt)comp_size;
7246 strm.next_out = out;
7247 strm.avail_out = (uInt)uncomp_size;
7248 if (inflateInit2(&strm, -MAX_WBITS) != Z_OK) {
7249 free(out);
7250 return NULL;
7251 }
7252 int ret = inflate(&strm, Z_FINISH);
7253 inflateEnd(&strm);
7254 if (ret != Z_STREAM_END) {
7255 free(out);
7256 return NULL;
7257 }
7258 *out_len = (int)strm.total_out;
7259 return out;
7260 }
7261 return NULL; /* unknown method */
7262}
7263
7264unsigned char *cbm_extract_binary_from_zip(const unsigned char *data, int data_len, int *out_len) {
7265 if (!data || data_len <= 0 || !out_len) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected