File: 0008-Added-a-guard-against-a-product-overflow-when-proces.patch

package info (click to toggle)
catdoc 1%3A0.95-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,456 kB
  • sloc: ansic: 3,920; sh: 327; tcl: 262; makefile: 188
file content (46 lines) | stat: -rw-r--r-- 1,347 bytes parent folder | download | duplicates (2)
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
42
43
44
45
46
From: Ali Rizvi-Santiago <arizvisa@gmail.com>
Date: Fri, 11 Apr 2025 12:08:44 -0500
Subject: Added a guard against a product overflow when processing "SST"
 records from the "Workbook" stream.

---
 src/xlsparse.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/xlsparse.c b/src/xlsparse.c
index 53fc21c..c44ac89 100644
--- a/src/xlsparse.c
+++ b/src/xlsparse.c
@@ -10,6 +10,8 @@
 #endif
 #include <stdlib.h>
 #include <string.h>
+#include <limits.h>
+#include <errno.h>
 #include "xls.h"
 #include "catdoc.h"
 #include "xltypes.h"
@@ -772,13 +774,21 @@ void parse_sst(unsigned char *sstbuf,int bufsize) {
 	unsigned char *barrier=(unsigned char *)sstbuf+bufsize; /*pointer to end of buffer*/
 	unsigned char **parsedString;/*pointer into parsed array*/ 
 			
-	sstsize = getlong(sstbuf+4,0);
+	sstsize = getlong(sstbuf+4,0);	// int
+
+	// Guard the next allocation against a product overflow.
+	if (!(sstsize < INT_MAX / sizeof(unsigned char*))) {
+		errno = EOVERFLOW;
+		perror("SST size error");
+		exit(1);
+	}
+
 	sst=(unsigned char **)malloc(sstsize*sizeof(unsigned char *));
-	
 	if (sst == NULL) {
 		perror("SST allocation error");
 		exit(1);
 	}
+
 	memset(sst,0,sstsize*sizeof(char *));
 	for (i=0,parsedString=sst,curString=sstbuf+8;
 			 i<sstsize && curString<barrier; i++,parsedString++) {