~ft/pdffs

ee8ac152c7ed0eb09e087212a4e521bb448c7831 — Sigrid Solveig Haflínudóttir 4 months ago c5a0818
ascii85: support z, validate each character, do NOT change the input buffer
1 files changed, 18 insertions(+), 8 deletions(-)

M f_ascii85.c
M f_ascii85.c => f_ascii85.c +18 -8
@@ 14,14 14,24 @@ flreadall(void *aux, Buffer *bi, Buffer *bo)
	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;