[packages/libhangul] Rel 3. Fix malformed hanja dictionary handling.
arekm
arekm at pld-linux.org
Thu Nov 26 09:06:00 CET 2026
commit 3831852a3cac50e7bdd56d6a070452de1ca720bb
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Thu Nov 26 00:27:00 2026 +0100
Rel 3. Fix malformed hanja dictionary handling.
Backport upstream fixes for a NULL pointer dereference on hanja
dictionary records without a value and for access to an empty key
table. Fixes CVE-2026-108063.
libhangul-hanja-tests.patch | 90 ++++++++++++++++++++++
libhangul-malformed-hanja.patch | 163 ++++++++++++++++++++++++++++++++++++++++
libhangul.spec | 6 +-
3 files changed, 258 insertions(+), 1 deletion(-)
---
diff --git a/libhangul.spec b/libhangul.spec
index 7d94e44..c92b1b4 100644
--- a/libhangul.spec
+++ b/libhangul.spec
@@ -7,12 +7,14 @@ Summary: Hangul input library
Summary(pl.UTF-8): Biblioteka wprowadzania znaków Hangul
Name: libhangul
Version: 0.2.0
-Release: 2
+Release: 3
License: LGPL v2.1+
Group: Libraries
#Source0Download: https://github.com/libhangul/libhangul/releases
Source0: https://github.com/libhangul/libhangul/releases/download/%{name}-%{version}/%{name}-%{version}.tar.gz
# Source0-md5: 074d78bf2dd9da73650e26c6a2a772bc
+Patch0: %{name}-malformed-hanja.patch
+Patch1: %{name}-hanja-tests.patch
URL: https://github.com/libhangul/libhangul
BuildRequires: check-devel
BuildRequires: gettext-tools >= 0.23.1
@@ -63,6 +65,8 @@ Dokumentacja API biblioteki libhangul.
%prep
%setup -q
+%patch -P0 -p1
+%patch -P1 -p1
%build
%configure \
diff --git a/libhangul-hanja-tests.patch b/libhangul-hanja-tests.patch
new file mode 100644
index 0000000..ea2ad8f
--- /dev/null
+++ b/libhangul-hanja-tests.patch
@@ -0,0 +1,90 @@
+From 23d2cd9d10d516d523d60c562dbcc7ea08139a09 Mon Sep 17 00:00:00 2001
+From: Choe Hwanjin <choe.hwanjin at gmail.com>
+Date: Sun, 11 Oct 2026 16:19:01 +0900
+Subject: [PATCH] test: add test cases for hanja dictionary file format
+
+Add test cases for loading records with incomplete fields.
+---
+ test/test.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 62 insertions(+)
+
+diff --git a/test/test.c b/test/test.c
+index 4a0dddd..23b980d 100644
+--- a/test/test.c
++++ b/test/test.c
+@@ -593,6 +593,64 @@ START_TEST(test_hangul_jamo_to_cjamo)
+ }
+ END_TEST
+
++static int
++test_hanja_table_format_helper(const char* content, const char* key)
++{
++ const char* filename = "test_hanja_format.txt";
++
++ size_t size = strlen(content);
++
++ FILE* fp = fopen(filename, "wb");
++ ck_assert(fp != NULL);
++ fwrite(content, 1, size, fp);
++ fclose(fp);
++
++ HanjaTable* table = hanja_table_load(filename);
++ ck_assert(table != NULL);
++
++ HanjaList* list = hanja_table_match_exact(table, key);
++ int res = hanja_list_get_size(list);
++ hanja_list_delete(list);
++
++ hanja_table_delete(table);
++ remove(filename);
++
++ return res;
++}
++
++START_TEST(test_hanja_table_format)
++{
++ /* https://github.com/libhangul/libhangul/issues/106 */
++ /* malformed entry: missing or incomplete value */
++ ck_assert(test_hanja_table_format_helper("", "key0") == 0);
++ ck_assert(test_hanja_table_format_helper("\n", "key0") == 0);
++ ck_assert(test_hanja_table_format_helper(":\n", "key0") == 0);
++ ck_assert(test_hanja_table_format_helper("::\n", "key0") == 0);
++ ck_assert(test_hanja_table_format_helper(":value0:\n", "key0") == 0);
++ ck_assert(test_hanja_table_format_helper(":value0:comment0\n", "key0") == 0);
++
++ ck_assert(test_hanja_table_format_helper("key0", "key0") == 0);
++ ck_assert(test_hanja_table_format_helper("key0:", "key0") == 0);
++ ck_assert(test_hanja_table_format_helper("key0::", "key0") == 0);
++ ck_assert(test_hanja_table_format_helper("key0::comment0", "key0") == 0);
++
++ ck_assert(test_hanja_table_format_helper("key0:value0", "key0") == 0);
++ ck_assert(test_hanja_table_format_helper("key0:value0\n", "key0") == 0);
++ ck_assert(test_hanja_table_format_helper("key0:value0\r", "key0") == 0);
++ ck_assert(test_hanja_table_format_helper("key0:value0\r\n", "key0") == 0);
++
++ ck_assert(test_hanja_table_format_helper("key0:value0:", "key0") == 1);
++ ck_assert(test_hanja_table_format_helper("key0:value0:\n", "key0") == 1);
++ ck_assert(test_hanja_table_format_helper("key0:value0:\r", "key0") == 1);
++ ck_assert(test_hanja_table_format_helper("key0:value0:\r\n", "key0") == 1);
++
++ ck_assert(test_hanja_table_format_helper("key0:value0:comment0", "key0") == 1);
++ ck_assert(test_hanja_table_format_helper("key0:value0:comment0\n", "key0") == 1);
++ ck_assert(test_hanja_table_format_helper("key0:value0:comment0\r", "key0") == 1);
++ ck_assert(test_hanja_table_format_helper("key0:value0:comment0\r\n", "key0") == 1);
++}
++END_TEST
++
+ Suite* libhangul_suite()
+ {
+ Suite* s = suite_create("libhangul");
+@@ -613,6 +671,10 @@ Suite* libhangul_suite()
+ tcase_add_test(hangul, test_hangul_jamo_to_cjamo);
+ suite_add_tcase(s, hangul);
+
++ TCase* hanja = tcase_create("hanja");
++ tcase_add_test(hanja, test_hanja_table_format);
++ suite_add_tcase(s, hanja);
++
+ return s;
+ }
+
diff --git a/libhangul-malformed-hanja.patch b/libhangul-malformed-hanja.patch
new file mode 100644
index 0000000..2b1dd96
--- /dev/null
+++ b/libhangul-malformed-hanja.patch
@@ -0,0 +1,163 @@
+# CVE-2026-108063: NULL dereference on malformed hanja dictionary, access to empty keytable
+# upstream commits 21c2931a8a5d + 911f30fa9be6 (libhangul#106)
+--- a/hangul/hanja.c
++++ b/hangul/hanja.c
+@@ -26,7 +26,6 @@
+ #include <unistd.h>
+ #else
+ #include <io.h>
+-#define strtok_r strtok_s
+ #endif
+
+ #ifdef HAVE_MMAP
+@@ -409,6 +408,9 @@
+ int low, high, mid;
+ int res = -1;
+
++ if (table->nkeys == 0 || table->keytable == NULL)
++ return;
++
+ low = 0;
+ high = table->nkeys - 1;
+
+@@ -437,10 +439,32 @@
+ fseek(table->file, offset, SEEK_SET);
+
+ while (fgets(buf, sizeof(buf), table->file) != NULL) {
+- char* save = NULL;
+- char* p = strtok_r(buf, ":", &save);
+- res = strcmp(p, key);
+- if (res == 0) {
++ char* k = buf;
++ char* p = strpbrk(k, ":");
++ if (p == NULL) { // no key
++ break;
++ }
++
++ p[0] = '\0';
++ p++;
++
++ res = strcmp(k, key);
++ if (res == 0) {
++ char* value = p;
++ p = strpbrk(value, ":");
++ if (p == NULL || p == value) { // no value
++ break;
++ }
++
++ p[0] = '\0';
++ p++;
++
++ char* comment = p;
++ p = strpbrk(comment, "\r\n");
++ if (p != NULL) {
++ p[0] = '\0';
++ }
++
+ if (*list == NULL) {
+ *list = hanja_list_new(key);
+ }
+@@ -449,12 +473,8 @@
+ break;
+ }
+
+- char* value = strtok_r(NULL, ":", &save);
+- char* comment = strtok_r(NULL, "\r\n", &save);
+-
+- Hanja* hanja = hanja_new(p, value, comment);
+-
+- hanja_list_append_n(*list, hanja, 1);
++ Hanja* hanja = hanja_new(k, value, comment);
++ hanja_list_append_n(*list, hanja, 1);
+ } else if (res > 0) {
+ break;
+ }
+@@ -486,12 +506,11 @@
+ char buf[512];
+ int key_size = 5;
+ char last_key[8] = { '\0', };
+- char* save_ptr = NULL;
+ char* key;
+ long offset;
+ unsigned i;
+ FILE* file;
+- HanjaIndex* keytable;
++ HanjaIndex* keytable = NULL;
+ HanjaTable* table;
+
+ if (filename == NULL)
+@@ -512,11 +531,12 @@
+ if (buf[0] == '#' || buf[0] == '\r' || buf[0] == '\n' || buf[0] == '\0')
+ continue;
+
+- save_ptr = NULL;
+- key = strtok_r(buf, ":", &save_ptr);
+-
+- if (key == NULL || strlen(key) == 0)
+- continue;
++ key = buf;
++ char* p = strpbrk(key, ":");
++ if (p == NULL || p == key) {
++ continue;
++ }
++ p[0] = '\0';
+
+ if (strncmp(last_key, key, key_size) != 0) {
+ nkeys++;
+@@ -525,29 +545,34 @@
+ }
+
+ rewind(file);
+- keytable = malloc(nkeys * sizeof(keytable[0]));
+- memset(keytable, 0, nkeys * sizeof(keytable[0]));
++ last_key[0] = '\0';
+
+- i = 0;
+- offset = ftell(file);
+- while (fgets(buf, sizeof(buf), file) != NULL) {
+- /* skip comments and empty lines */
+- if (buf[0] == '#' || buf[0] == '\r' || buf[0] == '\n' || buf[0] == '\0')
+- continue;
+-
+- save_ptr = NULL;
+- key = strtok_r(buf, ":", &save_ptr);
+-
+- if (key == NULL || strlen(key) == 0)
+- continue;
+-
+- if (strncmp(last_key, key, key_size) != 0) {
+- keytable[i].offset = offset;
+- strncpy(keytable[i].key, key, key_size);
+- strncpy(last_key, key, key_size);
+- i++;
+- }
+- offset = ftell(file);
++ if (nkeys > 0) {
++ keytable = malloc(nkeys * sizeof(keytable[0]));
++ memset(keytable, 0, nkeys * sizeof(keytable[0]));
++
++ i = 0;
++ offset = ftell(file);
++ while (fgets(buf, sizeof(buf), file) != NULL) {
++ /* skip comments and empty lines */
++ if (buf[0] == '#' || buf[0] == '\r' || buf[0] == '\n' || buf[0] == '\0')
++ continue;
++
++ key = buf;
++ char* p = strpbrk(key, ":");
++ if (p == NULL || p == key) {
++ continue;
++ }
++ p[0] = '\0';
++
++ if (strncmp(last_key, key, key_size) != 0) {
++ keytable[i].offset = offset;
++ strncpy(keytable[i].key, key, key_size);
++ strncpy(last_key, key, key_size);
++ i++;
++ }
++ offset = ftell(file);
++ }
+ }
+
+ table = malloc(sizeof(*table));
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/libhangul.git/commitdiff/3831852a3cac50e7bdd56d6a070452de1ca720bb
More information about the pld-cvs-commit
mailing list