[master] 2e91455d6 Sync libvgz with github/madler/zlib
Poul-Henning Kamp
phk at FreeBSD.org
Tue Jul 2 11:41:06 UTC 2024
commit 2e91455d6907b80938262d17697e55c4827f79fb
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Jul 2 11:40:26 2024 +0000
Sync libvgz with github/madler/zlib
diff --git a/lib/libvgz/deflate.c b/lib/libvgz/deflate.c
index a2b341d98..05a2d4517 100644
--- a/lib/libvgz/deflate.c
+++ b/lib/libvgz/deflate.c
@@ -501,7 +501,7 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
*/
s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, LIT_BUFS);
- s->pending_buf_size = (ulg)s->lit_bufsize * LIT_BUFS;
+ s->pending_buf_size = (ulg)s->lit_bufsize * 4; // Pretty sure this should be LIT_BUFS /phk
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
s->pending_buf == Z_NULL) {
@@ -735,6 +735,14 @@ int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) {
return Z_OK;
}
+/* ========================================================================= */
+int ZEXPORT deflateUsed(z_streamp strm, int *bits) {
+ if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
+ if (bits != Z_NULL)
+ *bits = strm->state->bi_used;
+ return Z_OK;
+}
+
/* ========================================================================= */
int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) {
deflate_state *s;
@@ -1743,7 +1751,7 @@ local block_state deflate_stored(deflate_state *s, int flush) {
s->strm->total_out += len;
}
} while (last == 0);
- if (last)
+ if (last)
s->strm->stop_bit =
(s->strm->total_out + s->pending) * 8 + s->bi_valid;
diff --git a/lib/libvgz/deflate.h b/lib/libvgz/deflate.h
index 720dca7e4..4d93b2acf 100644
--- a/lib/libvgz/deflate.h
+++ b/lib/libvgz/deflate.h
@@ -271,6 +271,9 @@ typedef struct internal_state {
/* Number of valid bits in bi_buf. All bits above the last valid bit
* are always zero.
*/
+ int bi_used;
+ /* Last number of used bits when going to a byte boundary.
+ */
ulg high_water;
/* High water mark offset in window for initialized bytes -- bytes above
diff --git a/lib/libvgz/inffast.c b/lib/libvgz/inffast.c
index 1f49bd5a5..f7b550b8b 100644
--- a/lib/libvgz/inffast.c
+++ b/lib/libvgz/inffast.c
@@ -155,7 +155,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
dist += (unsigned)hold & ((1U << op) - 1);
#ifdef INFLATE_STRICT
if (dist > dmax) {
- strm->msg = "invalid distance too far back";
+ strm->msg = (z_const char *)"invalid distance too far back";
state->mode = BAD;
break;
}
@@ -169,7 +169,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
if (op > whave) {
if (state->sane) {
strm->msg =
- "invalid distance too far back";
+ (z_const char *)"invalid distance too far back";
state->mode = BAD;
break;
}
@@ -265,7 +265,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
goto dodist;
}
else {
- strm->msg = "invalid distance code";
+ strm->msg = (z_const char *)"invalid distance code";
state->mode = BAD;
break;
}
@@ -280,7 +280,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
break;
}
else {
- strm->msg = "invalid literal/length code";
+ strm->msg = (z_const char *)"invalid literal/length code";
state->mode = BAD;
break;
}
diff --git a/lib/libvgz/inflate.c b/lib/libvgz/inflate.c
index 07a5f36c9..5c7494f47 100644
--- a/lib/libvgz/inflate.c
+++ b/lib/libvgz/inflate.c
@@ -647,12 +647,12 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
if (
#endif
((BITS(8) << 8) + (hold >> 8)) % 31) {
- strm->msg = "incorrect header check";
+ strm->msg = (z_const char *)"incorrect header check";
state->mode = BAD;
break;
}
if (BITS(4) != Z_DEFLATED) {
- strm->msg = "unknown compression method";
+ strm->msg = (z_const char *)"unknown compression method";
state->mode = BAD;
break;
}
@@ -661,7 +661,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
if (state->wbits == 0)
state->wbits = len;
if (len > 15 || len > state->wbits) {
- strm->msg = "invalid window size";
+ strm->msg = (z_const char *)"invalid window size";
state->mode = BAD;
break;
}
@@ -677,12 +677,12 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
NEEDBITS(16);
state->flags = (int)(hold);
if ((state->flags & 0xff) != Z_DEFLATED) {
- strm->msg = "unknown compression method";
+ strm->msg = (z_const char *)"unknown compression method";
state->mode = BAD;
break;
}
if (state->flags & 0xe000) {
- strm->msg = "unknown header flags set";
+ strm->msg = (z_const char *)"unknown header flags set";
state->mode = BAD;
break;
}
@@ -798,7 +798,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
if (state->flags & 0x0200) {
NEEDBITS(16);
if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
- strm->msg = "header crc mismatch";
+ strm->msg = (z_const char *)"header crc mismatch";
state->mode = BAD;
break;
}
@@ -865,7 +865,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
state->mode = TABLE;
break;
case 3:
- strm->msg = "invalid block type";
+ strm->msg = (z_const char *)"invalid block type";
state->mode = BAD;
}
DROPBITS(2);
@@ -874,7 +874,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
BYTEBITS(); /* go to byte boundary */
NEEDBITS(32);
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
- strm->msg = "invalid stored block lengths";
+ strm->msg = (z_const char *)"invalid stored block lengths";
state->mode = BAD;
break;
}
@@ -915,7 +915,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
DROPBITS(4);
#ifndef PKZIP_BUG_WORKAROUND
if (state->nlen > 286 || state->ndist > 30) {
- strm->msg = "too many length or distance symbols";
+ strm->msg = (z_const char *)"too many length or distance symbols";
state->mode = BAD;
break;
}
@@ -938,7 +938,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
ret = inflate_table(CODES, state->lens, 19, &(state->next),
&(state->lenbits), state->work);
if (ret) {
- strm->msg = "invalid code lengths set";
+ strm->msg = (z_const char *)"invalid code lengths set";
state->mode = BAD;
break;
}
@@ -962,7 +962,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
NEEDBITS(here.bits + 2);
DROPBITS(here.bits);
if (state->have == 0) {
- strm->msg = "invalid bit length repeat";
+ strm->msg = (z_const char *)"invalid bit length repeat";
state->mode = BAD;
break;
}
@@ -985,7 +985,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
DROPBITS(7);
}
if (state->have + copy > state->nlen + state->ndist) {
- strm->msg = "invalid bit length repeat";
+ strm->msg = (z_const char *)"invalid bit length repeat";
state->mode = BAD;
break;
}
@@ -999,7 +999,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
/* check for end-of-block code (better have one) */
if (state->lens[256] == 0) {
- strm->msg = "invalid code -- missing end-of-block";
+ strm->msg = (z_const char *)"invalid code -- missing end-of-block";
state->mode = BAD;
break;
}
@@ -1013,7 +1013,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
&(state->lenbits), state->work);
if (ret) {
- strm->msg = "invalid literal/lengths set";
+ strm->msg = (z_const char *)"invalid literal/lengths set";
state->mode = BAD;
break;
}
@@ -1022,7 +1022,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
&(state->next), &(state->distbits), state->work);
if (ret) {
- strm->msg = "invalid distances set";
+ strm->msg = (z_const char *)"invalid distances set";
state->mode = BAD;
break;
}
@@ -1076,7 +1076,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
break;
}
if (here.op & 64) {
- strm->msg = "invalid literal/length code";
+ strm->msg = (z_const char *)"invalid literal/length code";
state->mode = BAD;
break;
}
@@ -1114,7 +1114,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
DROPBITS(here.bits);
state->back += here.bits;
if (here.op & 64) {
- strm->msg = "invalid distance code";
+ strm->msg = (z_const char *)"invalid distance code";
state->mode = BAD;
break;
}
@@ -1131,7 +1131,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
}
#ifdef INFLATE_STRICT
if (state->offset > state->dmax) {
- strm->msg = "invalid distance too far back";
+ strm->msg = (z_const char *)"invalid distance too far back";
state->mode = BAD;
break;
}
@@ -1146,7 +1146,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
copy = state->offset - copy;
if (copy > state->whave) {
if (state->sane) {
- strm->msg = "invalid distance too far back";
+ strm->msg = (z_const char *)"invalid distance too far back";
state->mode = BAD;
break;
}
@@ -1205,7 +1205,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
state->flags ? hold :
#endif
ZSWAP32(hold)) != state->check) {
- strm->msg = "incorrect data check";
+ strm->msg = (z_const char *)"incorrect data check";
state->mode = BAD;
break;
}
@@ -1219,7 +1219,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
if (state->wrap && state->flags) {
NEEDBITS(32);
if ((state->wrap & 4) && hold != (state->total & 0xffffffff)) {
- strm->msg = "incorrect length check";
+ strm->msg = (z_const char *)"incorrect length check";
state->mode = BAD;
break;
}
diff --git a/lib/libvgz/trees.c b/lib/libvgz/trees.c
index bbaa24870..76e45b36d 100644
--- a/lib/libvgz/trees.c
+++ b/lib/libvgz/trees.c
@@ -184,6 +184,7 @@ local void bi_windup(deflate_state *s) {
} else if (s->bi_valid > 0) {
put_byte(s, (Byte)s->bi_buf);
}
+ s->bi_used = ((s->bi_valid - 1) & 7) + 1;
s->bi_buf = 0;
s->bi_valid = 0;
#ifdef ZLIB_DEBUG
@@ -466,6 +467,7 @@ void ZLIB_INTERNAL _tr_init(deflate_state *s) {
s->bi_buf = 0;
s->bi_valid = 0;
+ s->bi_used = 0;
#ifdef ZLIB_DEBUG
s->compressed_len = 0L;
s->bits_sent = 0L;
diff --git a/lib/libvgz/vgz.h b/lib/libvgz/vgz.h
index 97b140531..e339f0e10 100644
--- a/lib/libvgz/vgz.h
+++ b/lib/libvgz/vgz.h
@@ -602,11 +602,11 @@ ZEXTERN int ZEXPORT deflateInit2 (z_streamp strm,
Z_RLE is almost as fast as Z_HUFFMAN_ONLY, but should give better
compression for PNG image data than Huffman only. The degree of string
matching from most to none is: Z_DEFAULT_STRATEGY, Z_FILTERED, Z_RLE, then
- Z_HUFFMAN. The strategy parameter affects the compression ratio but never
- the correctness of the compressed output, even if it is not set optimally
- for the given data. Z_FIXED uses the default string matching, but prevents
- the use of dynamic Huffman codes, allowing for a simpler decoder for special
- applications.
+ Z_HUFFMAN_ONLY. The strategy parameter affects the compression ratio but
+ never the correctness of the compressed output, even if it is not set
+ optimally for the given data. Z_FIXED uses the default string matching, but
+ prevents the use of dynamic Huffman codes, allowing for a simpler decoder
+ for special applications.
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid
@@ -796,6 +796,18 @@ ZEXTERN int ZEXPORT deflatePending (z_streamp strm,
stream state was inconsistent.
*/
+ZEXTERN int ZEXPORT deflateUsed(z_streamp strm,
+ int *bits);
+/*
+ deflateUsed() returns in *bits the most recent number of deflate bits used
+ in the last byte when flushing to a byte boundary. The result is in 1..8, or
+ 0 if there has not yet been a flush. This helps determine the location of
+ the last bit of a deflate stream.
+
+ deflateUsed returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+ */
+
ZEXTERN int ZEXPORT deflatePrime (z_streamp strm,
int bits,
int value);
diff --git a/lib/libvgz/zconf.h b/lib/libvgz/zconf.h
index ea3b6d685..4a52aed7c 100644
--- a/lib/libvgz/zconf.h
+++ b/lib/libvgz/zconf.h
@@ -59,6 +59,7 @@
# define deflateSetDictionary z_deflateSetDictionary
# define deflateSetHeader z_deflateSetHeader
# define deflateTune z_deflateTune
+# define deflateUsed z_deflateUsed
# define deflate_copyright z_deflate_copyright
# define get_crc_table z_get_crc_table
# ifndef Z_SOLO
@@ -506,7 +507,7 @@ typedef uLong FAR uLongf;
#endif
#ifndef z_off_t
-# define z_off_t long
+# define z_off_t long long
#endif
#if !defined(_WIN32) && defined(Z_LARGE64)
diff --git a/tools/cmp_libz.sh b/tools/cmp_libz.sh
deleted file mode 100644
index b9c5c6b0d..000000000
--- a/tools/cmp_libz.sh
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/sh
-
-# This script compares libvgz to zlib in FreeBSD source tree
-
-LZ=/usr/src/contrib/zlib
-
-if [ ! -d lib/libvgz ] ; then
- echo "Run this from to of tree" 1>&2
- exit 2
-fi
-
-for i in lib/libvgz/*.[ch]
-do
- b=`basename $i`
- if [ "$b" == "vgz.h" ] ; then
- b="zlib.h"
- fi
- if [ -f ${LZ}/$b ] ; then
- echo "==== $b"
- sed '
- s/vgz.h/zlib.h/
- /strm->msg =/s/"/(char *)"/
- ' $i |
- diff -u ${LZ}/$b -
- else
- echo "#### $b #### NOT FOUND ####"
- fi
-done
diff --git a/tools/cmp_zlib.sh b/tools/cmp_zlib.sh
new file mode 100644
index 000000000..a3acbd2b8
--- /dev/null
+++ b/tools/cmp_zlib.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+# Compare libvgz with github/madler/zlib
+
+LZ=/tmp/zlib
+
+if [ "${LZ}" = "/tmp/zlib" -a ! -d ${LZ} ] ; then
+ rm -rf ${LZ}
+ git clone https://github.com/madler/zlib ${LZ}
+else
+ (cd ${LZ} && git pull)
+fi
+
+for i in varnish-cache/lib/libvgz/*.[ch]
+do
+ b=`basename $i`
+ if [ "$b" == "vgz.h" ] ; then
+ b="zlib.h"
+ fi
+ if [ -f ${LZ}/$b ] ; then
+ echo "#################################### $b"
+ sed '
+ s/vgz.h/zlib.h/
+ # /strm->msg =/s/"/(char *)"/
+ ' $i |
+ diff -wu - ${LZ}/$b
+ else
+ echo "#### $b #### NOT FOUND ####"
+ fi
+done
More information about the varnish-commit
mailing list