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

Function gf_batch_header

src/mcp/test_impact_git.c:1658–1688  ·  view source on GitHub ↗

Continue validating digits after overflow so a malformed suffix is never * mistaken for a valid huge size. Header length includes its terminal LF. */

Source from the content-addressed store, hash-verified

1656/* Continue validating digits after overflow so a malformed suffix is never
1657 * mistaken for a valid huge size. Header length includes its terminal LF. */
1658static bool gf_batch_header(cbm_git_facts_t *facts, cbm_git_bytes_t capture, const char *oid,
1659 size_t width, gf_batch_header_t *header, cbm_git_facts_error_t *error) {
1660 *header = (gf_batch_header_t){0};
1661 if (!gf_batch_gate(facts, error))
1662 return false;
1663 size_t begin = width + 6;
1664 if (capture.length < begin + 2 || memcmp(capture.data, oid, width) != 0 ||
1665 memcmp(capture.data + width, " blob ", 6) != 0)
1666 return gf_error(error, CBM_GIT_FACTS_COMMAND, "Malformed Git batch identity/type");
1667 size_t value = 0, at = begin;
1668 bool overflow = false;
1669 for (; at < capture.length && capture.data[at] != '\n'; at++) {
1670 if (((at - begin) & 65535u) == 0 && !gf_batch_gate(facts, error))
1671 return false;
1672 unsigned char c = capture.data[at];
1673 if (c < '0' || c > '9' || (at > begin && capture.data[begin] == '0'))
1674 return gf_error(error, CBM_GIT_FACTS_COMMAND, "Malformed Git batch object size");
1675 if (value > (SIZE_MAX - (size_t)(c - '0')) / 10)
1676 overflow = true;
1677 if (!overflow)
1678 value = value * 10 + (size_t)(c - '0');
1679 }
1680 if (at == begin || at == capture.length)
1681 return gf_error(error, CBM_GIT_FACTS_COMMAND, "Truncated Git batch header");
1682 if (overflow || at == SIZE_MAX - 1 || value > SIZE_MAX - (at + 1) - 1)
1683 return gf_batch_limit(facts, error, "Git batch object frame size overflow");
1684 if (!gf_batch_gate(facts, error))
1685 return false;
1686 *header = (gf_batch_header_t){.size = value, .length = at + 1};
1687 return true;
1688}
1689
1690static bool gf_batch_payload(cbm_git_facts_t *facts, cbm_git_bytes_t capture, size_t *offset,
1691 size_t size, cbm_git_bytes_t *bytes, cbm_git_facts_error_t *error) {

Callers 2

gf_batch_captureFunction · 0.85

Calls 3

gf_batch_gateFunction · 0.85
gf_errorFunction · 0.85
gf_batch_limitFunction · 0.85

Tested by

no test coverage detected