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

Function tar_try_extract_binary

src/cli/cli.c:2419–2442  ·  view source on GitHub ↗

Try to extract the target binary from a tar entry. Returns malloc'd data or NULL. */

Source from the content-addressed store, hash-verified

2417
2418/* Try to extract the target binary from a tar entry. Returns malloc'd data or NULL. */
2419static unsigned char *tar_try_extract_binary(const unsigned char *hdr, char typeflag,
2420 const char *name, const unsigned char *archive,
2421 size_t data_pos, long file_size, size_t total,
2422 int *out_len) {
2423 (void)hdr;
2424 if (typeflag != '0' && typeflag != '\0') {
2425 return NULL;
2426 }
2427 const char *basename = strrchr(name, '/');
2428 basename = basename ? basename + CLI_SKIP_ONE : name;
2429 if (strncmp(basename, TAR_BINARY_NAME, TAR_BINARY_NAME_LEN) != 0) {
2430 return NULL;
2431 }
2432 if (data_pos + (size_t)file_size > total) {
2433 return NULL;
2434 }
2435 unsigned char *result = malloc((size_t)file_size);
2436 if (!result) {
2437 return NULL;
2438 }
2439 memcpy(result, archive + data_pos, (size_t)file_size);
2440 *out_len = (int)file_size;
2441 return result;
2442}
2443
2444unsigned char *cbm_extract_binary_from_targz(const unsigned char *data, int data_len,
2445 int *out_len) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected