Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit876b37d

Browse files
committed
Fix buffer allocations in encoding conversion routines so that they won't
fail on zero-length inputs. This isn't an issue in normal use because theconversion infrastructure skips calling the converters for empty strings.However a problem was created by yesterday's patch to check whether theright conversion function is supplied in CREATE CONVERSION. The mostfuture-proof fix seems to be to make the converters safe for this corner case.
1 parent21eb6ae commit876b37d

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

‎src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c

Lines changed: 13 additions & 13 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/cyrillic_and_mic/cyrillic_and_mic.c,v 1.19 2009/01/29 19:23:39 tgl Exp $
9+
* $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c,v 1.20 2009/02/28 18:49:42 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -203,7 +203,7 @@ koi8r_to_win1251(PG_FUNCTION_ARGS)
203203

204204
CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R,PG_WIN1251);
205205

206-
buf=palloc(len*ENCODING_GROWTH_RATE);
206+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
207207
koi8r2mic(src,buf,len);
208208
mic2win1251(buf,dest,strlen((char*)buf));
209209
pfree(buf);
@@ -221,7 +221,7 @@ win1251_to_koi8r(PG_FUNCTION_ARGS)
221221

222222
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251,PG_KOI8R);
223223

224-
buf=palloc(len*ENCODING_GROWTH_RATE);
224+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
225225
win12512mic(src,buf,len);
226226
mic2koi8r(buf,dest,strlen((char*)buf));
227227
pfree(buf);
@@ -239,7 +239,7 @@ koi8r_to_win866(PG_FUNCTION_ARGS)
239239

240240
CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R,PG_WIN866);
241241

242-
buf=palloc(len*ENCODING_GROWTH_RATE);
242+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
243243
koi8r2mic(src,buf,len);
244244
mic2win866(buf,dest,strlen((char*)buf));
245245
pfree(buf);
@@ -257,7 +257,7 @@ win866_to_koi8r(PG_FUNCTION_ARGS)
257257

258258
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN866,PG_KOI8R);
259259

260-
buf=palloc(len*ENCODING_GROWTH_RATE);
260+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
261261
win8662mic(src,buf,len);
262262
mic2koi8r(buf,dest,strlen((char*)buf));
263263
pfree(buf);
@@ -281,7 +281,7 @@ win866_to_win1251(PG_FUNCTION_ARGS)
281281
* not in KOI8R. As we use MULE_INTERNAL/KOI8R as an intermediary, we
282282
* will fail to convert those characters.
283283
*/
284-
buf=palloc(len*ENCODING_GROWTH_RATE);
284+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
285285
win8662mic(src,buf,len);
286286
mic2win1251(buf,dest,strlen((char*)buf));
287287
pfree(buf);
@@ -300,7 +300,7 @@ win1251_to_win866(PG_FUNCTION_ARGS)
300300
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251,PG_WIN866);
301301

302302
/* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
303-
buf=palloc(len*ENCODING_GROWTH_RATE);
303+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
304304
win12512mic(src,buf,len);
305305
mic2win866(buf,dest,strlen((char*)buf));
306306
pfree(buf);
@@ -318,7 +318,7 @@ iso_to_koi8r(PG_FUNCTION_ARGS)
318318

319319
CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5,PG_KOI8R);
320320

321-
buf=palloc(len*ENCODING_GROWTH_RATE);
321+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
322322
iso2mic(src,buf,len);
323323
mic2koi8r(buf,dest,strlen((char*)buf));
324324
pfree(buf);
@@ -336,7 +336,7 @@ koi8r_to_iso(PG_FUNCTION_ARGS)
336336

337337
CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R,PG_ISO_8859_5);
338338

339-
buf=palloc(len*ENCODING_GROWTH_RATE);
339+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
340340
koi8r2mic(src,buf,len);
341341
mic2iso(buf,dest,strlen((char*)buf));
342342
pfree(buf);
@@ -355,7 +355,7 @@ iso_to_win1251(PG_FUNCTION_ARGS)
355355
CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5,PG_WIN1251);
356356

357357
/* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
358-
buf=palloc(len*ENCODING_GROWTH_RATE);
358+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
359359
iso2mic(src,buf,len);
360360
mic2win1251(buf,dest,strlen((char*)buf));
361361
pfree(buf);
@@ -374,7 +374,7 @@ win1251_to_iso(PG_FUNCTION_ARGS)
374374
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251,PG_ISO_8859_5);
375375

376376
/* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
377-
buf=palloc(len*ENCODING_GROWTH_RATE);
377+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
378378
win12512mic(src,buf,len);
379379
mic2iso(buf,dest,strlen((char*)buf));
380380
pfree(buf);
@@ -393,7 +393,7 @@ iso_to_win866(PG_FUNCTION_ARGS)
393393
CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5,PG_WIN866);
394394

395395
/* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
396-
buf=palloc(len*ENCODING_GROWTH_RATE);
396+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
397397
iso2mic(src,buf,len);
398398
mic2win866(buf,dest,strlen((char*)buf));
399399
pfree(buf);
@@ -412,7 +412,7 @@ win866_to_iso(PG_FUNCTION_ARGS)
412412
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN866,PG_ISO_8859_5);
413413

414414
/* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
415-
buf=palloc(len*ENCODING_GROWTH_RATE);
415+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
416416
win8662mic(src,buf,len);
417417
mic2iso(buf,dest,strlen((char*)buf));
418418
pfree(buf);

‎src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c

Lines changed: 1 addition & 3 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/euc_jp_and_sjis/euc_jp_and_sjis.c,v 1.21 2009/01/29 19:23:39 tgl Exp $
9+
* $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c,v 1.22 2009/02/28 18:49:42 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -27,8 +27,6 @@
2727
*/
2828
#include"sjis.map"
2929

30-
#defineENCODING_GROWTH_RATE 4
31-
3230
PG_MODULE_MAGIC;
3331

3432
PG_FUNCTION_INFO_V1(euc_jp_to_sjis);

‎src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c

Lines changed: 3 additions & 3 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/euc_tw_and_big5/euc_tw_and_big5.c,v 1.20 2009/01/29 19:23:39 tgl Exp $
9+
* $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c,v 1.21 2009/02/28 18:49:42 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -59,7 +59,7 @@ euc_tw_to_big5(PG_FUNCTION_ARGS)
5959

6060
CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_TW,PG_BIG5);
6161

62-
buf=palloc(len*ENCODING_GROWTH_RATE);
62+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
6363
euc_tw2mic(src,buf,len);
6464
mic2big5(buf,dest,strlen((char*)buf));
6565
pfree(buf);
@@ -77,7 +77,7 @@ big5_to_euc_tw(PG_FUNCTION_ARGS)
7777

7878
CHECK_ENCODING_CONVERSION_ARGS(PG_BIG5,PG_EUC_TW);
7979

80-
buf=palloc(len*ENCODING_GROWTH_RATE);
80+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
8181
big52mic(src,buf,len);
8282
mic2euc_tw(buf,dest,strlen((char*)buf));
8383
pfree(buf);

‎src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c

Lines changed: 3 additions & 3 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/latin2_and_win1250/latin2_and_win1250.c,v 1.17 2009/01/29 19:23:39 tgl Exp $
9+
* $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c,v 1.18 2009/02/28 18:49:42 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -115,7 +115,7 @@ latin2_to_win1250(PG_FUNCTION_ARGS)
115115

116116
CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN2,PG_WIN1250);
117117

118-
buf=palloc(len*ENCODING_GROWTH_RATE);
118+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
119119
latin22mic(src,buf,len);
120120
mic2win1250(buf,dest,strlen((char*)buf));
121121
pfree(buf);
@@ -133,7 +133,7 @@ win1250_to_latin2(PG_FUNCTION_ARGS)
133133

134134
CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1250,PG_LATIN2);
135135

136-
buf=palloc(len*ENCODING_GROWTH_RATE);
136+
buf=palloc(len*ENCODING_GROWTH_RATE+1);
137137
win12502mic(src,buf,len);
138138
mic2latin2(buf,dest,strlen((char*)buf));
139139
pfree(buf);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp