From 3379fee1bc390997ce9428a11024c4885dc71b84 Mon Sep 17 00:00:00 2001 From: Thomas Loimer Date: Fri, 2 Apr 2021 17:13:55 +0200 Subject: [PATCH 1/7] Correctly return the status of popen() calls When converting a fig file to a bitmap, and writing to a device with too little space, the exit status of fig2dev was zero. Therefore, when exporting from xfig, xfig could not note that something went wrong. This might resolve part of the problem reported in ticket [#101]. --- fig2dev/dev/genbitmaps.c | 6 +++++- fig2dev/dev/readeps.c | 5 +++-- fig2dev/dev/readpics.c | 9 +++++++-- fig2dev/dev/readppm.c | 4 +++- version.m4 | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/fig2dev/dev/genbitmaps.c b/fig2dev/dev/genbitmaps.c index a6a804d..e478ba5 100644 --- a/fig2dev/dev/genbitmaps.c +++ b/fig2dev/dev/genbitmaps.c @@ -3,7 +3,7 @@ * Copyright (c) 1991 by Micah Beck * Parts Copyright (c) 1985-1988 by Supoj Sutanthavibul * Parts Copyright (c) 1989-2015 by Brian V. Smith - * Parts Copyright (c) 2015-2020 by Thomas Loimer + * Parts Copyright (c) 2015-2021 by Thomas Loimer * * Any party obtaining a copy of these files is granted, free of charge, a * full and unrestricted irrevocable, world-wide, paid up, royalty-free, @@ -533,6 +533,10 @@ genbitmaps_end(void) } status = pclose(tfp); + if (WIFEXITED(status)) + status = WEXITSTATUS(status); + else + status = -1; tfp = NULL; /* Otherwise main() tries to close tfp again */ (void) signal(SIGPIPE, SIG_DFL); diff --git a/fig2dev/dev/readeps.c b/fig2dev/dev/readeps.c index 1436f7b..a7d6008 100644 --- a/fig2dev/dev/readeps.c +++ b/fig2dev/dev/readeps.c @@ -3,7 +3,7 @@ * Copyright (c) 1991 by Micah Beck * Parts Copyright (c) 1985-1988 by Supoj Sutanthavibul * Parts Copyright (c) 1989-2015 by Brian V. Smith - * Parts Copyright (c) 2015-2020 by Thomas Loimer + * Parts Copyright (c) 2015-2021 by Thomas Loimer * * Any party obtaining a copy of these files is granted, free of charge, a * full and unrestricted irrevocable, world-wide, paid up, royalty-free, @@ -85,7 +85,8 @@ gsexe(FILE **out, bool *isnew, char *exenew, char *exeold) n = fscanf(fp, "%lf", &rev); stat = pclose(fp); if (n != 1 || stat != 0) - return stat == 0 ? failure : stat; + return stat == 0 ? failure : (WIFEXITED(stat) ? + WEXITSTATUS(stat) : failure); if (rev > 9.49) { exe = exenew; diff --git a/fig2dev/dev/readpics.c b/fig2dev/dev/readpics.c index 67cfe19..7f27307 100644 --- a/fig2dev/dev/readpics.c +++ b/fig2dev/dev/readpics.c @@ -3,7 +3,7 @@ * Copyright (c) 1991 by Micah Beck * Parts Copyright (c) 1985-1988 by Supoj Sutanthavibul * Parts Copyright (c) 1989-2015 by Brian V. Smith - * Parts Copyright (c) 2015-2019 by Thomas Loimer + * Parts Copyright (c) 2015-2021 by Thomas Loimer * * Any party obtaining a copy of these files is granted, free of charge, a * full and unrestricted irrevocable, world-wide, paid up, royalty-free, @@ -253,12 +253,17 @@ close_stream(struct xfig_stream *restrict xf_stream) } else { /* a pipe */ char trash[BUFSIZ]; + int status; /* for a pipe, must read everything or we'll get a broken pipe message */ while (fread(trash, (size_t)1, (size_t)BUFSIZ, xf_stream->fp) == (size_t)BUFSIZ) ; - return pclose(xf_stream->fp); + status = pclose(xf_stream->fp); + if (WIFEXITED(status)) + return WEXITSTATUS(status); + else + return -1; } } diff --git a/fig2dev/dev/readppm.c b/fig2dev/dev/readppm.c index 16dd025..e2c1d1c 100644 --- a/fig2dev/dev/readppm.c +++ b/fig2dev/dev/readppm.c @@ -3,7 +3,7 @@ * Copyright (c) 1991 by Micah Beck * Parts Copyright (c) 1985-1988 by Supoj Sutanthavibul * Parts Copyright (c) 1989-2015 by Brian V. Smith - * Parts Copyright (c) 2015-2020 by Thomas Loimer + * Parts Copyright (c) 2015-2021 by Thomas Loimer * * Any party obtaining a copy of these files is granted, free of charge, a * full and unrestricted irrevocable, world-wide, paid up, royalty-free, @@ -326,6 +326,8 @@ read_ppm(F_pic *pic, struct xfig_stream *restrict pic_stream, int *llx,int *lly) stat = -1; } remove(pcxname); + } else { + stat = -1; } if (pcxname != pcxname_buf) -- 2.31.1 From 43cfa693284b076e5d2cc100758a34b76db65e58 Mon Sep 17 00:00:00 2001 From: Thomas Loimer Date: Fri, 23 Apr 2021 22:31:27 +0200 Subject: [PATCH 2/7] Remove arrows from polygon with single point, ticket #114 When sanitizing line objects, a polygon consisting of too few points is converted to a polyline. With this commit, the resulting polyline is also sanitized, e.g, by removing arrow tips if the line consists only of a single point. --- fig2dev/read.c | 3 ++- fig2dev/tests/read.at | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/fig2dev/read.c b/fig2dev/read.c index c12d3a0..7e18fda 100644 --- a/fig2dev/read.c +++ b/fig2dev/read.c @@ -3,7 +3,7 @@ * Copyright (c) 1991 by Micah Beck * Parts Copyright (c) 1985-1988 by Supoj Sutanthavibul * Parts Copyright (c) 1989-2015 by Brian V. Smith - * Parts Copyright (c) 2015-2020 by Thomas Loimer + * Parts Copyright (c) 2015-2021 by Thomas Loimer * * Any party obtaining a copy of these files is granted, free of charge, a * full and unrestricted irrevocable, world-wide, paid up, royalty-free, @@ -936,6 +936,7 @@ sanitize_lineobject( put_msg("A polygon with %d points at line %d - convert to a polyline.", npts, line_no); l->type = T_POLYLINE; + sanitize_lineobject(l, p, line_no); return 0; } } diff --git a/fig2dev/tests/read.at b/fig2dev/tests/read.at index 4b2d80f..f43cc80 100644 --- a/fig2dev/tests/read.at +++ b/fig2dev/tests/read.at @@ -2,7 +2,7 @@ dnl Fig2dev: Translate Fig code to various Devices dnl Copyright (c) 1991 by Micah Beck dnl Parts Copyright (c) 1985-1988 by Supoj Sutanthavibul dnl Parts Copyright (c) 1989-2015 by Brian V. Smith -dnl Parts Copyright (c) 2015-2020 by Thomas Loimer +dnl Parts Copyright (c) 2015-2021 by Thomas Loimer dnl dnl Any party obtaining a copy of these files is granted, free of charge, a dnl full and unrestricted irrevocable, world-wide, paid up, royalty-free, @@ -121,7 +121,7 @@ EOF ]) AT_CLEANUP -AT_SETUP([remove arrows tips from single point]) +AT_SETUP([remove arrow tips from single point]) AT_KEYWORDS(read.c polyline) AT_CHECK([fig2dev -L pict2e < Date: Sat, 24 Apr 2021 10:29:59 +0200 Subject: [PATCH 3/7] Allow truncated sub/superscripts in text, #113, #117 For svg output, sub- and superscripts are indicated by the ^ and _ characters, respectively. A text string truncated right after these characters caused buffer overflow. Fixes tickets #113 and #117. --- fig2dev/dev/gensvg.c | 8 ++++++-- fig2dev/tests/output.at | 11 +++++++++++ fig2dev/tests/read.at | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/fig2dev/dev/gensvg.c b/fig2dev/dev/gensvg.c index e888dbf..1ff0a06 100644 --- a/fig2dev/dev/gensvg.c +++ b/fig2dev/dev/gensvg.c @@ -3,7 +3,7 @@ * Parts Copyright (c) 2002 by Anthony Starks * Parts Copyright (c) 2002-2006 by Martin Kroeker * Parts Copyright (c) 2002-2015 by Brian V. Smith - * Parts Copyright (c) 2015-2020 by Thomas Loimer + * Parts Copyright (c) 2015-2021 by Thomas Loimer * * Any party obtaining a copy of these files is granted, free of charge, a * full and unrestricted irrevocable, world-wide, paid up, royalty-free, @@ -1005,7 +1005,7 @@ gensvg_text(F_text *t) #endif for (cp = (unsigned char *)t->cstring; *cp; cp++) { ch = *cp; - if (( supsub == 2 &&ch == '}' ) || supsub==1) { + if ((supsub == 2 && ch == '}') || supsub==1) { #ifdef NOSUPER fprintf(tfp,"",-dy); old_dy=-dy; @@ -1019,6 +1019,8 @@ gensvg_text(F_text *t) } } if (ch == '_' || ch == '^') { + if (*(cp + 1) == '\0') + break; supsub=1; #ifdef NOSUPER if (dy != 0) @@ -1043,6 +1045,8 @@ gensvg_text(F_text *t) ++cp; ch = *cp; if (ch == '{' ) { + if (*(cp + 1) == '\0') + break; supsub=2; ++cp; ch = *cp; diff --git a/fig2dev/tests/output.at b/fig2dev/tests/output.at index e6408d7..0918961 100644 --- a/fig2dev/tests/output.at +++ b/fig2dev/tests/output.at @@ -231,6 +231,17 @@ AT_CHECK([SOURCE_DATE_EPOCH=1483564881 fig2dev -L svg \ - $builddir/data/fillswclip.svg]) AT_CLEANUP +AT_SETUP([truncated sub/superscript, tickets #113, #117]) +AT_KEYWORDS(read.c svg) +AT_CHECK([fig2dev -L svg < Date: Sat, 24 Apr 2021 23:04:36 +0200 Subject: [PATCH 4/7] Omit arrows without points in svg output, ticket #115 --- fig2dev/dev/gensvg.c | 4 ++-- fig2dev/tests/output.at | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/fig2dev/dev/gensvg.c b/fig2dev/dev/gensvg.c index 1ff0a06..2c30d8c 100644 --- a/fig2dev/dev/gensvg.c +++ b/fig2dev/dev/gensvg.c @@ -1173,7 +1173,7 @@ svg_arrows(int line_thickness, F_arrow *for_arrow, F_arrow *back_arrow, return true; } - if (for_arrow) { + if (for_arrow && fnpoints > 1) { fputs("