aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-09-27 07:40:46 +0800
committerGitHub <noreply@github.com>2024-09-26 23:40:46 +0000
commita9287dd882e082a17fc7dcf004d3f991ed29001b (patch)
treeeafd77075b02bd7aef20cdceb6097636edb97b12
parent98d1c0ebef77ba2d96f1203ad504b8ae08ebdab0 (diff)
downloadrneovim-a9287dd882e082a17fc7dcf004d3f991ed29001b.tar.gz
rneovim-a9287dd882e082a17fc7dcf004d3f991ed29001b.tar.bz2
rneovim-a9287dd882e082a17fc7dcf004d3f991ed29001b.zip
fix(mbyte): check for utf8proc_map() failure (#30531)
-rw-r--r--src/nvim/mbyte.c10
-rw-r--r--test/unit/mbyte_spec.lua6
2 files changed, 13 insertions, 3 deletions
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index e1701bb931..05f81c48a9 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -1380,11 +1380,15 @@ int utf_fold(int a)
}
utf8proc_uint8_t input_str[16] = { 0 };
- utf8proc_encode_char(a, input_str);
+ if (utf8proc_encode_char(a, input_str) <= 0) {
+ return a;
+ }
utf8proc_uint8_t *fold_str_utf;
- utf8proc_map((utf8proc_uint8_t *)input_str, 0, &fold_str_utf,
- UTF8PROC_NULLTERM | UTF8PROC_CASEFOLD);
+ if (utf8proc_map((utf8proc_uint8_t *)input_str, 0, &fold_str_utf,
+ UTF8PROC_NULLTERM | UTF8PROC_CASEFOLD) < 0) {
+ return a;
+ }
int fold_codepoint_utf = utf_ptr2char((char *)fold_str_utf);
diff --git a/test/unit/mbyte_spec.lua b/test/unit/mbyte_spec.lua
index 62390c8794..e0c0244989 100644
--- a/test/unit/mbyte_spec.lua
+++ b/test/unit/mbyte_spec.lua
@@ -347,4 +347,10 @@ describe('mbyte', function()
check('L̓̉̑̒̌̚ơ̗̌̒̄̀ŕ̈̈̎̐̕è̇̅̄̄̐m̖̟̟̅̄̚', {'L̓̉̑̒̌̚', 'ơ̗̌̒̄̀', 'ŕ̈̈̎̐̕', 'è̇̅̄̄̐', 'm̖̟̟̅̄̚'})
-- stylua: ignore end
end)
+
+ describe('utf_fold', function()
+ itp('does not crash with surrogates #30527', function()
+ eq(0xDDFB, lib.utf_fold(0xDDFB))
+ end)
+ end)
end)