mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
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:
parent
dd8a4e2c22
commit
a2e5c2f7c8
@ -1360,6 +1360,10 @@ retry:
|
||||
u8c += (unsigned)(*--p) << 16;
|
||||
u8c += (unsigned)(*--p) << 24;
|
||||
}
|
||||
// Replace characters over INT_MAX with Unicode replacement character
|
||||
if (u8c > INT_MAX) {
|
||||
u8c = 0xfffd;
|
||||
}
|
||||
} else { // UTF-8
|
||||
if (*--p < 0x80) {
|
||||
u8c = *p;
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user