mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00: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:
@@ -1360,6 +1360,10 @@ retry:
|
|||||||
u8c += (unsigned)(*--p) << 16;
|
u8c += (unsigned)(*--p) << 16;
|
||||||
u8c += (unsigned)(*--p) << 24;
|
u8c += (unsigned)(*--p) << 24;
|
||||||
}
|
}
|
||||||
|
// Replace characters over INT_MAX with Unicode replacement character
|
||||||
|
if (u8c > INT_MAX) {
|
||||||
|
u8c = 0xfffd;
|
||||||
|
}
|
||||||
} else { // UTF-8
|
} else { // UTF-8
|
||||||
if (*--p < 0x80) {
|
if (*--p < 0x80) {
|
||||||
u8c = *p;
|
u8c = *p;
|
||||||
|
@@ -15,6 +15,7 @@ local read_file = helpers.read_file
|
|||||||
local trim = helpers.trim
|
local trim = helpers.trim
|
||||||
local currentdir = helpers.funcs.getcwd
|
local currentdir = helpers.funcs.getcwd
|
||||||
local iswin = helpers.iswin
|
local iswin = helpers.iswin
|
||||||
|
local assert_alive = helpers.assert_alive
|
||||||
|
|
||||||
describe('fileio', function()
|
describe('fileio', function()
|
||||||
before_each(function()
|
before_each(function()
|
||||||
@@ -26,6 +27,7 @@ describe('fileio', function()
|
|||||||
os.remove('Xtest_startup_file1~')
|
os.remove('Xtest_startup_file1~')
|
||||||
os.remove('Xtest_startup_file2')
|
os.remove('Xtest_startup_file2')
|
||||||
os.remove('Xtest_тест.md')
|
os.remove('Xtest_тест.md')
|
||||||
|
os.remove('Xtest-u8-int-max')
|
||||||
rmdir('Xtest_startup_swapdir')
|
rmdir('Xtest_startup_swapdir')
|
||||||
rmdir('Xtest_backupdir')
|
rmdir('Xtest_backupdir')
|
||||||
end)
|
end)
|
||||||
@@ -128,5 +130,12 @@ describe('fileio', function()
|
|||||||
table.insert(text, '')
|
table.insert(text, '')
|
||||||
eq(text, funcs.readfile(fname, 'b'))
|
eq(text, funcs.readfile(fname, 'b'))
|
||||||
end)
|
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)
|
end)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user