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

Function tar_try_extract_binary

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

6164
6165/* Try to extract the target binary from a tar entry. Returns malloc'd data or NULL. */
6166static unsigned char *tar_try_extract_binary(const unsigned char *hdr, char typeflag,
6167 const char *name, const unsigned char *archive,
6168 size_t data_pos, long file_size, size_t total,
6169 int *out_len) {
6170 (void)hdr;
6171 if (typeflag != '0' && typeflag != '\0') {
6172 return NULL;
6173 }
6174 const char *basename = strrchr(name, '/');
6175 basename = basename ? basename + CLI_SKIP_ONE : name;
6176 if (strncmp(basename, TAR_BINARY_NAME, TAR_BINARY_NAME_LEN) != 0) {
6177 return NULL;
6178 }
6179 if (data_pos + (size_t)file_size > total) {
6180 return NULL;
6181 }
6182 unsigned char *result = malloc((size_t)file_size);
6183 if (!result) {
6184 return NULL;
6185 }
6186 memcpy(result, archive + data_pos, (size_t)file_size);
6187 *out_len = (int)file_size;
6188 return result;
6189}
6190
6191unsigned char *cbm_extract_binary_from_targz(const unsigned char *data, int data_len,
6192 int *out_len) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected