1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-28 07:50:48 -08:00

Fix 'treesit-max-buffer-size' and its use

* lisp/treesit.el (treesit-max-buffer-size): Avoid overflow in
computing buffer-size limit.  Account for 32-but systems built
"--with-wide-int".  Extend doc string.
(treesit-ready-p): Compare the limit with the size of the buffer
in bytes, not in characters.

* src/treesit.c (treesit_check_buffer_size): Measure buffer size
in bytes.
This commit is contained in:
Eli Zaretskii 2022-11-22 20:22:41 +02:00
parent fa567684fa
commit 368d2531be
2 changed files with 14 additions and 8 deletions

View file

@ -840,11 +840,11 @@ treesit_ensure_position_synced (Lisp_Object parser)
static void
treesit_check_buffer_size (struct buffer *buffer)
{
ptrdiff_t buffer_size = (BUF_Z (buffer) - BUF_BEG (buffer));
if (buffer_size > UINT32_MAX)
ptrdiff_t buffer_size_bytes = (BUF_Z_BYTE (buffer) - BUF_BEG_BYTE (buffer));
if (buffer_size_bytes > UINT32_MAX)
xsignal2 (Qtreesit_buffer_too_large,
build_pure_c_string ("Buffer size cannot be larger than 4GB"),
make_fixnum (buffer_size));
make_fixnum (buffer_size_bytes));
}
static Lisp_Object treesit_make_ranges (const TSRange *, uint32_t, struct buffer *);