From: Tatsuo Ishii Date: Sat, 24 Dec 2005 00:49:18 +0000 (+0000) Subject: Fix for rearranging encoding id ISO-8859-5 to ISO-8859-8. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=701232c92b3868ca6aa602471d5aa51ea6953d40;p=users%2Fbernd%2Fpostgres.git Fix for rearranging encoding id ISO-8859-5 to ISO-8859-8. Also make the code more robust by searching for target encoding in the internal charset map. Problem reported by Sagi Bashari on 2005/12/21. See "[BUGS] BUG #2120: Crash when doing UTF8<->ISO_8859_8 encoding conversion" on pgsql-bugs list for more details. Back patch for 8.1_STABLE. --- diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c b/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c index f431bf9ea2..409775a299 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c @@ -68,15 +68,6 @@ typedef struct } pg_conv_map; static pg_conv_map maps[] = { - {PG_SQL_ASCII}, /* SQL/ASCII */ - {PG_EUC_JP}, /* EUC for Japanese */ - {PG_EUC_CN}, /* EUC for Chinese */ - {PG_EUC_KR}, /* EUC for Korean */ - {PG_EUC_TW}, /* EUC for Taiwan */ - {PG_JOHAB}, /* EUC for Korean JOHAB */ - {PG_UTF8}, /* Unicode UTF8 */ - {PG_MULE_INTERNAL}, /* Mule internal code */ - {PG_LATIN1}, /* ISO-8859-1 Latin 1 */ {PG_LATIN2, LUmapISO8859_2, ULmapISO8859_2, sizeof(LUmapISO8859_2) / sizeof(pg_local_to_utf), sizeof(ULmapISO8859_2) / sizeof(pg_utf_to_local)}, /* ISO-8859-2 Latin 2 */ @@ -104,12 +95,6 @@ static pg_conv_map maps[] = { {PG_LATIN10, LUmapISO8859_16, ULmapISO8859_16, sizeof(LUmapISO8859_16) / sizeof(pg_local_to_utf), sizeof(ULmapISO8859_16) / sizeof(pg_utf_to_local)}, /* ISO-8859-16 Latin 10 */ - {PG_WIN1256}, /* windows-1256 */ - {PG_WIN1258}, /* Windows-1258 */ - {PG_WIN874}, /* windows-874 */ - {PG_KOI8R}, /* KOI8-R */ - {PG_WIN1251}, /* windows-1251 */ - {PG_WIN866}, /* (MS-DOS CP866) */ {PG_ISO_8859_5, LUmapISO8859_5, ULmapISO8859_5, sizeof(LUmapISO8859_5) / sizeof(pg_local_to_utf), sizeof(ULmapISO8859_5) / sizeof(pg_utf_to_local)}, /* ISO-8859-5 */ @@ -131,11 +116,23 @@ iso8859_to_utf8(PG_FUNCTION_ARGS) unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2); unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); int len = PG_GETARG_INT32(4); + int i; Assert(PG_GETARG_INT32(1) == PG_UTF8); Assert(len >= 0); - LocalToUtf(src, dest, maps[encoding].map1, maps[encoding].size1, encoding, len); + for (i=0;i= 0); - UtfToLocal(src, dest, maps[encoding].map2, maps[encoding].size2, len); + for (i=0;i