diff options
author | vanaigr <vanaigranov@gmail.com> | 2024-09-03 08:01:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-03 06:01:42 -0700 |
commit | d1d7d5468091fc71fb85c090da87253efdfcdf08 (patch) | |
tree | 404b0db12463d37978d1db87a74aaae74ae48d3c /test/functional/api/buffer_spec.lua | |
parent | ceddaedfadae80996fb4852bfca86fe8929ab454 (diff) | |
download | rneovim-d1d7d5468091fc71fb85c090da87253efdfcdf08.tar.gz rneovim-d1d7d5468091fc71fb85c090da87253efdfcdf08.tar.bz2 rneovim-d1d7d5468091fc71fb85c090da87253efdfcdf08.zip |
fix(api): nvim_buf_get_text() crashes with large negative column #28740
Problem:
crash when calling nvim_buf_get_text() with a large negative start_col:
call nvim_buf_get_text(0, 0, -123456789, 0, 0, {})
Solution:
clamp start_col after subtracting it from the line length.
Diffstat (limited to 'test/functional/api/buffer_spec.lua')
-rw-r--r-- | test/functional/api/buffer_spec.lua | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index f836c1c540..3775c8c7b7 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -1891,6 +1891,8 @@ describe('api/buf', function() eq({ '' }, get_text(0, 0, 18, 0, 20, {})) eq({ 'ext' }, get_text(0, -2, 1, -2, 4, {})) eq({ 'hello foo!', 'text', 'm' }, get_text(0, 0, 0, 2, 1, {})) + eq({ 'hello foo!' }, get_text(0, 0, -987654321, 0, 987654321, {})) + eq({ '' }, get_text(0, 0, -15, 0, -20, {})) end) it('errors on out-of-range', function() @@ -1904,7 +1906,7 @@ describe('api/buf', function() it('errors when start is greater than end', function() eq("'start' is higher than 'end'", pcall_err(get_text, 0, 1, 0, 0, 0, {})) - eq('start_col must be less than end_col', pcall_err(get_text, 0, 0, 1, 0, 0, {})) + eq('start_col must be less than or equal to end_col', pcall_err(get_text, 0, 0, 1, 0, 0, {})) end) end) |