From c7501c82237380bbe03646e6f4133b4862bec5a8 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 8 Oct 2008 20:35:39 +0000 Subject: [PATCH] Bug 554790 - g_convert() misbehaves with winiconv versions 2008-10-08 Tor Lillqvist Bug 554790 - g_convert() misbehaves with winiconv versions * glib/win_iconv.c (kernel_mbtowc): If converting from ASCII, explicitly check for and reject 8bit chars. MultiByteToWideChar() doesn't, at least not on XP. svn path=/trunk/; revision=7578 --- ChangeLog | 8 ++++++++ glib/win_iconv.c | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2ae8d2326..9bf3daf57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-10-08 Tor Lillqvist + + Bug 554790 - g_convert() misbehaves with winiconv versions + + * glib/win_iconv.c (kernel_mbtowc): If converting from ASCII, + explicitly check for and reject 8bit chars. MultiByteToWideChar() + doesn't, at least not on XP. + 2008-10-06 Matthias Clasen * glib/gtypes.h: Properly include gmacros.h diff --git a/glib/win_iconv.c b/glib/win_iconv.c index b8ee71099..ea1924024 100644 --- a/glib/win_iconv.c +++ b/glib/win_iconv.c @@ -1362,6 +1362,12 @@ kernel_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wb len = cv->mblen(cv, buf, bufsize); if (len == -1) return -1; + /* If converting from ASCII, reject 8bit + * chars. MultiByteToWideChar() doesn't. Note that for ASCII we + * know that the mblen function is sbcs_mblen() so len is 1. + */ + if (cv->codepage == 20127 && buf[0] >= 0x80) + return_error(EILSEQ); *wbufsize = MultiByteToWideChar(cv->codepage, mbtowc_flags (cv->codepage), (const char *)buf, len, (wchar_t *)wbuf, *wbufsize); if (*wbufsize == 0)