File: 09_pdf_read.patch

package info (click to toggle)
xfig 1%3A3.2.8b-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 27,428 kB
  • sloc: ansic: 75,823; sh: 3,174; makefile: 303; javascript: 22; csh: 5
file content (41 lines) | stat: -rw-r--r-- 1,484 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From: Thomas Loimer <thomas.loimer@tuwien.ac.at>
Date: Fri, 8 Jul 2022 12:14:41 +0200
Origin: upstream, https://sourceforge.net/p/mcj/xfig/ci/c784438, https://sourceforge.net/p/mcj/xfig/ci/3813c1e
Bug: https://sourceforge.net/p/mcj/tickets/143/
Subject: Read pdf without crash, ticket #143
 Reading a pdf for embedding as a picture would crash when compiled with
 -fsanitize=address. Ticket #143 describes probably the same issue.

--- a/src/f_readeps.c
+++ b/src/f_readeps.c
@@ -121,6 +121,7 @@ correct_boundingbox(int *llx, int *lly,
 int
 read_pdf(F_pic *pic, struct xfig_stream *restrict pic_stream)
 {
+	char	locale[64] = "C";
 	char	*savelocale;
 	/* prime with an invalid bounding box */
 	int	llx = 0, lly = 0, urx = 0, ury = 0;
@@ -137,16 +138,17 @@ read_pdf(F_pic *pic, struct xfig_stream
 	 */
 #ifdef I18N
 	savelocale = setlocale(LC_NUMERIC, NULL);
-	if (strcmp(savelocale, "C") && strcmp(savelocale, "POSIX"))
+	if (strlen(savelocale) < sizeof locale)
+		strcpy(locale, savelocale);
+
+	if (strcmp(locale, "C") && strcmp(locale, "POSIX"))
 		setlocale(LC_NUMERIC, "C");
-	else
-		savelocale = "";
 #endif
 	if (scan_mediabox(pic_stream->content, &llx, &lly, &urx, &ury))
 		gs_mediabox(pic_stream->content, &llx, &lly, &urx, &ury);
 #ifdef I18N
-	if (*savelocale)
-		setlocale(LC_NUMERIC, savelocale);
+	if (strcmp(locale, "C") && strcmp(locale, "POSIX"))
+		setlocale(LC_NUMERIC, locale);
 #endif
 
 	/* provide A4 or Letter bounding box, if reading /MediaBox fails */