Skip to content

Commit 5b2c46a

Browse files
committed
msLayoutTextSymbol(): fix memory corruption in case of failed iconv() (#5025)
1 parent 084be4d commit 5b2c46a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Diff for: textlayout.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ int msLayoutTextSymbol(mapObj *map, textSymbolObj *ts, textPathObj *tgret) {
435435
#endif
436436
struct line_desc static_line_descs[STATIC_LINES];
437437
int alloc_glyphs = 0;
438-
struct line_desc *line_descs;
438+
struct line_desc *line_descs = NULL;
439439
text_run *runs;
440440
double oldpeny=3455,peny,penx=0; /*oldpeny is set to an unreasonable default initial value */
441441
fontSetObj *fontset = NULL;
@@ -469,8 +469,6 @@ int msLayoutTextSymbol(mapObj *map, textSymbolObj *ts, textPathObj *tgret) {
469469
while(len>0) {
470470
iconv_status = iconv(cd, &inp, &len, &outp, &bufleft);
471471
if(iconv_status == -1) {
472-
iconv_close(cd);
473-
free(encoded_text);
474472
break;
475473
}
476474
}
@@ -486,6 +484,9 @@ int msLayoutTextSymbol(mapObj *map, textSymbolObj *ts, textPathObj *tgret) {
486484
text_num_bytes = strlen(ts->annotext);
487485
}
488486

487+
if( text_num_bytes == 0 )
488+
return 0;
489+
489490
if(text_num_bytes > STATIC_GLYPHS) {
490491
#ifdef USE_FRIBIDI
491492
glyphs.bidi_levels = msSmallMalloc(text_num_bytes * sizeof(FriBidiLevel));

0 commit comments

Comments
 (0)