Skip to content

Commit dcc7da8

Browse files
committed
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.
1 parent ea9b028 commit dcc7da8

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
* IDENTIFICATION
9-
* $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 $
9+
* $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 $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -68,15 +68,6 @@ typedef struct
6868
} pg_conv_map;
6969

7070
static pg_conv_map maps[] = {
71-
{PG_SQL_ASCII}, /* SQL/ASCII */
72-
{PG_EUC_JP}, /* EUC for Japanese */
73-
{PG_EUC_CN}, /* EUC for Chinese */
74-
{PG_EUC_KR}, /* EUC for Korean */
75-
{PG_EUC_TW}, /* EUC for Taiwan */
76-
{PG_JOHAB}, /* EUC for Korean JOHAB */
77-
{PG_UTF8}, /* Unicode UTF8 */
78-
{PG_MULE_INTERNAL}, /* Mule internal code */
79-
{PG_LATIN1}, /* ISO-8859-1 Latin 1 */
8071
{PG_LATIN2, LUmapISO8859_2, ULmapISO8859_2,
8172
sizeof(LUmapISO8859_2) / sizeof(pg_local_to_utf),
8273
sizeof(ULmapISO8859_2) / sizeof(pg_utf_to_local)}, /* ISO-8859-2 Latin 2 */
@@ -104,12 +95,6 @@ static pg_conv_map maps[] = {
10495
{PG_LATIN10, LUmapISO8859_16, ULmapISO8859_16,
10596
sizeof(LUmapISO8859_16) / sizeof(pg_local_to_utf),
10697
sizeof(ULmapISO8859_16) / sizeof(pg_utf_to_local)}, /* ISO-8859-16 Latin 10 */
107-
{PG_WIN1256}, /* windows-1256 */
108-
{PG_WIN1258}, /* Windows-1258 */
109-
{PG_WIN874}, /* windows-874 */
110-
{PG_KOI8R}, /* KOI8-R */
111-
{PG_WIN1251}, /* windows-1251 */
112-
{PG_WIN866}, /* (MS-DOS CP866) */
11398
{PG_ISO_8859_5, LUmapISO8859_5, ULmapISO8859_5,
11499
sizeof(LUmapISO8859_5) / sizeof(pg_local_to_utf),
115100
sizeof(ULmapISO8859_5) / sizeof(pg_utf_to_local)}, /* ISO-8859-5 */
@@ -131,11 +116,23 @@ iso8859_to_utf8(PG_FUNCTION_ARGS)
131116
unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
132117
unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
133118
int len = PG_GETARG_INT32(4);
119+
int i;
134120

135121
Assert(PG_GETARG_INT32(1) == PG_UTF8);
136122
Assert(len >= 0);
137123

138-
LocalToUtf(src, dest, maps[encoding].map1, maps[encoding].size1, encoding, len);
124+
for (i=0;i<sizeof(maps)/sizeof(pg_conv_map);i++)
125+
{
126+
if (encoding == maps[i].encoding)
127+
{
128+
LocalToUtf(src, dest, maps[i].map1, maps[i].size1, encoding, len);
129+
PG_RETURN_VOID();
130+
}
131+
}
132+
133+
ereport(ERROR,
134+
(errcode(ERRCODE_INTERNAL_ERROR),
135+
errmsg("unexpected encoding id %d for ISO-8859 charsets", encoding)));
139136

140137
PG_RETURN_VOID();
141138
}
@@ -147,11 +144,23 @@ utf8_to_iso8859(PG_FUNCTION_ARGS)
147144
unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
148145
unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
149146
int len = PG_GETARG_INT32(4);
147+
int i;
150148

151149
Assert(PG_GETARG_INT32(0) == PG_UTF8);
152150
Assert(len >= 0);
153151

154-
UtfToLocal(src, dest, maps[encoding].map2, maps[encoding].size2, len);
152+
for (i=0;i<sizeof(maps)/sizeof(pg_conv_map);i++)
153+
{
154+
if (encoding == maps[i].encoding)
155+
{
156+
UtfToLocal(src, dest, maps[i].map2, maps[i].size2, len);
157+
PG_RETURN_VOID();
158+
}
159+
}
160+
161+
ereport(ERROR,
162+
(errcode(ERRCODE_INTERNAL_ERROR),
163+
errmsg("unexpected encoding id %d for ISO-8859 charsets", encoding)));
155164

156165
PG_RETURN_VOID();
157166
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy