From dcc7da8d5e0854b4a17d3929c722b1afacafcef2 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Fri, 23 Dec 2005 02:11:02 +0000 Subject: [PATCH] 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. --- .../utf8_and_iso8859/utf8_and_iso8859.c | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) 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 e1600a1fee..13de37b558 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 @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c,v 1.16 2005/11/22 18:17:26 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c,v 1.17 2005/12/23 02:11:02 ishii Exp $ * *------------------------------------------------------------------------- */ @@ -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