shithub: pdffs

Download patch

ref: ee8ac152c7ed0eb09e087212a4e521bb448c7831
parent: c5a081872fe23806498b05fc8cb72261aaf0d007
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Jun 3 02:27:34 EDT 2021

ascii85: support z, validate each character, do NOT change the input buffer

--- a/f_ascii85.c
+++ b/f_ascii85.c
@@ -14,14 +14,24 @@
 	USED(aux);
 
 	in = bufdata(bi, &insz);
-	for(i = j = 0; i < insz; i++){
-		if(!isws(in[i]))
-			in[j++] = in[i];
-	}
-	insz = j;
-	for(i = 0; i < insz; i += 5){
-		for(x = 0, j = 0; j < 5; j++)
-			x = x*85 + ((i+j < insz ? in[i+j] : 'u') - 33);
+	for(i = 0; i < insz;){
+		if(isws(in[i])){
+			i++;
+			continue;
+		}
+
+		if(in[i] == 'z'){
+			x = 0;
+			i++;
+		}else{
+			for(x = 0, j = 0; j < 5; j++, i++){
+				if(in[i] < '!' || in[i] > 'u'){
+					werrstr("invalid ascii85 char 0x%02x", in[i]);
+					return -1;
+				}
+				x = x*85 + ((i < insz ? in[i] : 'u') - '!');
+			}
+		}
 		c[0] = x >> 24;
 		c[1] = x >> 16;
 		c[2] = x >> 8;