mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-11-09 09:11:00 +08:00
fix: pad source read buffers in all parse passes (tree-sitter lookahead)
Same fix as read_file in pass_definitions: the calls/usages/semantic/k8s/lsp_cross passes each read a source file into a malloc'd buffer and re-parse it, so they hit the same tree-sitter lexer over-read past EOF under ASan. Over-allocate by 16 and zero the tail in every reader.
This commit is contained in:
@@ -46,7 +46,9 @@ static char *read_file(const char *path, int *out_len) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *buf = malloc(size + SKIP_ONE);
|
||||
/* +pad: tree-sitter lexer lookahead reads past EOF; keep it in-bounds */
|
||||
enum { CBM_TS_LOOKAHEAD_PAD = 16 };
|
||||
char *buf = malloc((size_t)size + CBM_TS_LOOKAHEAD_PAD);
|
||||
if (!buf) {
|
||||
(void)fclose(f);
|
||||
return NULL;
|
||||
@@ -58,7 +60,7 @@ static char *read_file(const char *path, int *out_len) {
|
||||
if (nread > (size_t)size) {
|
||||
nread = (size_t)size;
|
||||
}
|
||||
buf[nread] = '\0';
|
||||
memset(buf + nread, 0, CBM_TS_LOOKAHEAD_PAD);
|
||||
*out_len = (int)nread;
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,9 @@ static char *k8s_read_file(const char *path, int *out_len) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *buf = malloc(size + SKIP_ONE);
|
||||
/* +pad: tree-sitter lexer lookahead reads past EOF; keep it in-bounds */
|
||||
enum { CBM_TS_LOOKAHEAD_PAD = 16 };
|
||||
char *buf = malloc((size_t)size + CBM_TS_LOOKAHEAD_PAD);
|
||||
if (!buf) {
|
||||
(void)fclose(f);
|
||||
return NULL;
|
||||
@@ -55,7 +57,7 @@ static char *k8s_read_file(const char *path, int *out_len) {
|
||||
if (nread > (size_t)size) {
|
||||
nread = (size_t)size;
|
||||
}
|
||||
buf[nread] = '\0';
|
||||
memset(buf + nread, 0, CBM_TS_LOOKAHEAD_PAD);
|
||||
*out_len = (int)nread;
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,9 @@ static char *pxc_read_file(const char *path, int *out_len) {
|
||||
(void)fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
char *buf = (char *)malloc((size_t)size + 1);
|
||||
/* +pad: tree-sitter lexer lookahead reads past EOF; keep it in-bounds */
|
||||
enum { CBM_TS_LOOKAHEAD_PAD = 16 };
|
||||
char *buf = (char *)malloc((size_t)size + CBM_TS_LOOKAHEAD_PAD);
|
||||
if (!buf) {
|
||||
(void)fclose(f);
|
||||
return NULL;
|
||||
@@ -73,7 +75,7 @@ static char *pxc_read_file(const char *path, int *out_len) {
|
||||
(void)fclose(f);
|
||||
if (nread > (size_t)size)
|
||||
nread = (size_t)size;
|
||||
buf[nread] = '\0';
|
||||
memset(buf + nread, 0, CBM_TS_LOOKAHEAD_PAD);
|
||||
*out_len = (int)nread;
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,9 @@ static char *read_file(const char *path, int *out_len) {
|
||||
(void)fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
char *buf = malloc(size + SKIP_ONE);
|
||||
/* +pad: tree-sitter lexer lookahead reads past EOF; keep it in-bounds */
|
||||
enum { CBM_TS_LOOKAHEAD_PAD = 16 };
|
||||
char *buf = malloc((size_t)size + CBM_TS_LOOKAHEAD_PAD);
|
||||
if (!buf) {
|
||||
(void)fclose(f);
|
||||
return NULL;
|
||||
@@ -46,7 +48,7 @@ static char *read_file(const char *path, int *out_len) {
|
||||
if (nread > (size_t)size) {
|
||||
nread = (size_t)size;
|
||||
}
|
||||
buf[nread] = '\0';
|
||||
memset(buf + nread, 0, CBM_TS_LOOKAHEAD_PAD);
|
||||
*out_len = (int)nread;
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,9 @@ static char *read_file(const char *path, int *out_len) {
|
||||
(void)fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
char *buf = malloc(size + SKIP_ONE);
|
||||
/* +pad: tree-sitter lexer lookahead reads past EOF; keep it in-bounds */
|
||||
enum { CBM_TS_LOOKAHEAD_PAD = 16 };
|
||||
char *buf = malloc((size_t)size + CBM_TS_LOOKAHEAD_PAD);
|
||||
if (!buf) {
|
||||
(void)fclose(f);
|
||||
return NULL;
|
||||
@@ -46,7 +48,7 @@ static char *read_file(const char *path, int *out_len) {
|
||||
if (nread > (size_t)size) {
|
||||
nread = (size_t)size;
|
||||
}
|
||||
buf[nread] = '\0';
|
||||
memset(buf + nread, 0, CBM_TS_LOOKAHEAD_PAD);
|
||||
*out_len = (int)nread;
|
||||
return buf;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user