Skip to content

Commit 084be4d

Browse files
committed
Fix wrong use of iconv() that caused encoded_text pointer to be moved and corrupted (#5025)
1 parent b762546 commit 084be4d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

textlayout.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,10 @@ int msLayoutTextSymbol(mapObj *map, textSymbolObj *ts, textPathObj *tgret) {
451451
if(ts->label->encoding && strcasecmp(ts->label->encoding,"UTF-8")) {
452452
iconv_t cd;
453453
size_t len, iconv_status,bufleft;
454-
char *encoded_text,**outp;
454+
char *encoded_text,*outp;
455455
len = strlen(ts->annotext);
456-
bufleft = len*6 + 1;
457-
encoded_text = msSmallMalloc(bufleft);
456+
bufleft = len*6;
457+
encoded_text = msSmallMalloc(bufleft+1);
458458
cd = iconv_open("UTF-8", ts->label->encoding);
459459

460460
if(cd == (iconv_t)-1) {
@@ -464,19 +464,19 @@ int msLayoutTextSymbol(mapObj *map, textSymbolObj *ts, textPathObj *tgret) {
464464
}
465465

466466
inp = ts->annotext;
467-
outp = &encoded_text;
467+
outp = encoded_text;
468468

469469
while(len>0) {
470-
iconv_status = iconv(cd, &inp, &len, outp, &bufleft);
470+
iconv_status = iconv(cd, &inp, &len, &outp, &bufleft);
471471
if(iconv_status == -1) {
472472
iconv_close(cd);
473473
free(encoded_text);
474474
break;
475475
}
476476
}
477477

478-
text_num_bytes = len*6 - bufleft;
479-
encoded_text[text_num_bytes+1] = 0;
478+
text_num_bytes = outp - encoded_text;
479+
encoded_text[text_num_bytes] = 0;
480480
free(ts->annotext);
481481
ts->annotext = encoded_text;
482482
iconv_close(cd);

0 commit comments

Comments
 (0)