[master] 91e130fe8 Revert last two changes, I totally misunderstood why there are two buffers.

Poul-Henning Kamp phk at FreeBSD.org
Mon Aug 15 09:26:05 UTC 2022


commit 91e130fe8f095406782c5142637b8f4b367461f2
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Aug 15 09:24:37 2022 +0000

    Revert last two changes, I totally misunderstood why there are two buffers.
    
    Add a comment so nobody makes that mistake again.
    
    Also: Dont trust brain to work in heat-wave.

diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index 7f7e95ac3..245fcd87c 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -523,7 +523,7 @@ static int v_matchproto_(vdp_bytes_f)
 ved_pretend_gzip_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
     const void *pv, ssize_t l)
 {
-	uint8_t buf[5];
+	uint8_t buf1[5], buf2[5];
 	const uint8_t *p;
 	uint16_t lx;
 	struct ecx *ecx;
@@ -541,22 +541,34 @@ ved_pretend_gzip_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
 	ecx->crc = crc32(ecx->crc, p, l);
 	ecx->l_crc += l;
 
+	/*
+	 * buf1 can safely be emitted multiple times for objects longer
+	 * than 64K-1 bytes.
+	 */
+	lx = 65535;
+	buf1[0] = 0;
+	vle16enc(buf1 + 1, lx);
+	vle16enc(buf1 + 3, ~lx);
+
 	while (l > 0) {
-		if (l >= 65535)
+		if (l >= 65535) {
 			lx = 65535;
-		else
+			if (ved_bytes(ecx, VDP_NULL, buf1, sizeof buf1))
+				return (-1);
+		} else {
 			lx = (uint16_t)l;
-		buf[0] = 0;
-		vle16enc(buf + 1, lx);
-		vle16enc(buf + 3, ~lx);
-		if (ved_bytes(ecx, VDP_NULL, buf, sizeof buf))
-			return (-1);
+			buf2[0] = 0;
+			vle16enc(buf2 + 1, lx);
+			vle16enc(buf2 + 3, ~lx);
+			if (ved_bytes(ecx, VDP_NULL, buf2, sizeof buf2))
+				return (-1);
+		}
 		if (ved_bytes(ecx, VDP_NULL, p, lx))
 			return (-1);
 		l -= lx;
 		p += lx;
 	}
-	/* buf1 & buf2 is local, have to flush */
+	/* buf1 & buf2 are local, so we have to flush */
 	return (ved_bytes(ecx, VDP_FLUSH, NULL, 0));
 }
 


More information about the varnish-commit mailing list