mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +00:00
treesitter: check for integer overflow (#12135)
Sometimes treesitter calls for an invalid column within a line, checking that the column is actually valid and forcing the value avoids an integer overflow and an infinite sequence of invalid reads. Fixes #12131
This commit is contained in:
@@ -271,17 +271,22 @@ static const char *input_cb(void *payload, uint32_t byte_index,
|
|||||||
}
|
}
|
||||||
char_u *line = ml_get_buf(bp, position.row+1, false);
|
char_u *line = ml_get_buf(bp, position.row+1, false);
|
||||||
size_t len = STRLEN(line);
|
size_t len = STRLEN(line);
|
||||||
size_t tocopy = MIN(len-position.column, BUFSIZE);
|
|
||||||
|
|
||||||
memcpy(buf, line+position.column, tocopy);
|
if (position.column > len) {
|
||||||
// Translate embedded \n to NUL
|
*bytes_read = 0;
|
||||||
memchrsub(buf, '\n', '\0', tocopy);
|
} else {
|
||||||
*bytes_read = (uint32_t)tocopy;
|
size_t tocopy = MIN(len-position.column, BUFSIZE);
|
||||||
if (tocopy < BUFSIZE) {
|
|
||||||
// now add the final \n. If it didn't fit, input_cb will be called again
|
memcpy(buf, line+position.column, tocopy);
|
||||||
// on the same line with advanced column.
|
// Translate embedded \n to NUL
|
||||||
buf[tocopy] = '\n';
|
memchrsub(buf, '\n', '\0', tocopy);
|
||||||
(*bytes_read)++;
|
*bytes_read = (uint32_t)tocopy;
|
||||||
|
if (tocopy < BUFSIZE) {
|
||||||
|
// now add the final \n. If it didn't fit, input_cb will be called again
|
||||||
|
// on the same line with advanced column.
|
||||||
|
buf[tocopy] = '\n';
|
||||||
|
(*bytes_read)++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return buf;
|
return buf;
|
||||||
#undef BUFSIZE
|
#undef BUFSIZE
|
||||||
|
Reference in New Issue
Block a user