From 83f35f50cad8d9c6db424384659a6822e35da40c Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Wed, 9 Sep 2026 22:20:34 +0200 Subject: [PATCH] libatalk: reserve space for Unicode decomposition terminator Reported-by: Pavel Kohout (@pavelkohout396) Signed-off-by: Daniel Markstedt Reviewed-by: Andy Lemin (@andylemin) diff --git a/libatalk/unicode/util_unistr.c b/libatalk/unicode/util_unistr.c index 13a457f0d..2d257a6e3 100644 --- a/libatalk/unicode/util_unistr.c +++ b/libatalk/unicode/util_unistr.c @@ -710,7 +710,8 @@ size_t decompose_w(ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen) comb[COMBBUFLEN - comblen + 1] = result_sp & 0xFFFF; /* lo */ } while (comblen < MAXCOMBSPLEN); - if (*outlen < (comblen + 1) << 1) { + /* Reserve space for the lower code unit and terminator below. */ + if (*outlen < (comblen + 3) << 1) { errno = E2BIG; return (size_t) -1; } @@ -736,7 +737,8 @@ size_t decompose_w(ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen) } while ((0x007f < base) && (comblen < MAXCOMBLEN)); } - if (*outlen < (comblen + 1) << 1) { + /* Reserve space for the UTF-16 terminator below. */ + if (*outlen < (comblen + 2) << 1) { errno = E2BIG; return (size_t) -1; }