libutil/iconv: avoid overflow in surrogate pairs
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 5 Jul 2023 02:32:05 +0000 (14:32 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 26 Oct 2023 01:24:32 +0000 (01:24 +0000)
commit3960eabca781e892eb8fb12cde5bb3272f0ba366
treefed3290224ace3b110d775187f8759aeb5149385
parent949fe5707774fdc655b8430b0de805aa21004622
libutil/iconv: avoid overflow in surrogate pairs

Consider the non-conforment utf-8 sequence "\xf5\x80\x80\x80", which
would encode 0x140000. We would set the high byte of the first
surrogate to 0xd8 | (0x130000 >> 18), or 0xdc, which is an invalid
start for a high surrogate, making the sequence as a whole invalid (as
you would expect -- the Unicode range was set precisely to that
covered by utf-16 surrogates).

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/util/charset/iconv.c