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

Function tar_try_extract_binary

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

6108
6109/* Try to extract the target binary from a tar entry. Returns malloc'd data or NULL. */
6110static unsigned char *tar_try_extract_binary(const unsigned char *hdr, char typeflag,
6111 const char *name, const unsigned char *archive,
6112 size_t data_pos, long file_size, size_t total,
6113 int *out_len) {
6114 (void)hdr;
6115 if (typeflag != '0' && typeflag != '\0') {
6116 return NULL;
6117 }
6118 const char *basename = strrchr(name, '/');
6119 basename = basename ? basename + CLI_SKIP_ONE : name;
6120 if (strncmp(basename, TAR_BINARY_NAME, TAR_BINARY_NAME_LEN) != 0) {
6121 return NULL;
6122 }
6123 if (data_pos + (size_t)file_size > total) {
6124 return NULL;
6125 }
6126 unsigned char *result = malloc((size_t)file_size);
6127 if (!result) {
6128 return NULL;
6129 }
6130 memcpy(result, archive + data_pos, (size_t)file_size);
6131 *out_len = (int)file_size;
6132 return result;
6133}
6134
6135unsigned char *cbm_extract_binary_from_targz(const unsigned char *data, int data_len,
6136 int *out_len) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected