fix(fileio): replace characters over INT_MAX with U+FFFD (#16354)

fixes #11877
credit: @zubairabid https://github.com/neovim/neovim/pull/12010
This commit is contained in:
Javier Lopez
2021-11-23 23:07:47 -05:00
committed by GitHub
parent dd8a4e2c22
commit a2e5c2f7c8
2 changed files with 13 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ local read_file = helpers.read_file
local trim = helpers.trim
local currentdir = helpers.funcs.getcwd
local iswin = helpers.iswin
local assert_alive = helpers.assert_alive
describe('fileio', function()
before_each(function()
@@ -26,6 +27,7 @@ describe('fileio', function()
os.remove('Xtest_startup_file1~')
os.remove('Xtest_startup_file2')
os.remove('Xtest_тест.md')
os.remove('Xtest-u8-int-max')
rmdir('Xtest_startup_swapdir')
rmdir('Xtest_backupdir')
end)
@@ -128,5 +130,12 @@ describe('fileio', function()
table.insert(text, '')
eq(text, funcs.readfile(fname, 'b'))
end)
it('read invalid u8 over INT_MAX doesn\'t segfault', function()
clear()
command('call writefile(0zFFFFFFFF, "Xtest-u8-int-max")')
-- This should not segfault
command('edit ++enc=utf32 Xtest-u8-int-max')
assert_alive()
end)
end)