VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/zlib/gzwrite.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/zlib/gzwrite.c')
-rw-r--r--src/Common/zlib/gzwrite.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/Common/zlib/gzwrite.c b/src/Common/zlib/gzwrite.c
index c7b5651d..a8ffc8f5 100644
--- a/src/Common/zlib/gzwrite.c
+++ b/src/Common/zlib/gzwrite.c
@@ -1,6 +1,6 @@
/* gzwrite.c -- zlib functions for writing gzip files
- * Copyright (C) 2004-2017 Mark Adler
+ * Copyright (C) 2004-2019 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "gzguts.h"
@@ -96,8 +96,17 @@ local int gz_comp(state, flush)
}
return 0;
}
+ /* check for a pending reset */
+ if (state->reset) {
+ /* don't start a new gzip member unless there is data to write */
+ if (strm->avail_in == 0)
+ return 0;
+ deflateReset(strm);
+ state->reset = 0;
+ }
+
/* run deflate() on provided input until it produces no more output */
ret = Z_OK;
do {
/* write out current buffer contents if full, or if flushing, but if
@@ -133,9 +142,9 @@ local int gz_comp(state, flush)
} while (have);
/* if that completed a deflate stream, allow another to start */
if (flush == Z_FINISH)
- deflateReset(strm);
+ state->reset = 1;
/* all done, no errors */
return 0;
}
@@ -208,9 +217,9 @@ local z_size_t gz_write(state, buf, len)
have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
state->in);
copy = state->size - have;
if (copy > len)
- copy = len;
+ copy = (unsigned)len;
memcpy(state->in + have, buf, copy);
state->strm.avail_in += copy;
state->x.pos += copy;
buf = (const char *)buf + copy;
@@ -228,9 +237,9 @@ local z_size_t gz_write(state, buf, len)
state->strm.next_in = (z_const Bytef *)buf;
do {
unsigned n = (unsigned)-1;
if (n > len)
- n = len;
+ n = (unsigned)len;
state->strm.avail_in = n;
state->x.pos += n;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
@@ -348,14 +357,13 @@ int ZEXPORT gzputc(file, c)
return c & 0xff;
}
/* -- see zlib.h -- */
-int ZEXPORT gzputs(file, str)
+int ZEXPORT gzputs(file, s)
gzFile file;
- const char *str;
+ const char *s;
{
- int ret;
- z_size_t len;
+ z_size_t len, put;
gz_statep state;
/* get internal structure */
if (file == NULL)
@@ -366,11 +374,15 @@ int ZEXPORT gzputs(file, str)
if (state->mode != GZ_WRITE || state->err != Z_OK)
return -1;
/* write string */
- len = strlen(str);
- ret = gz_write(state, str, len);
- return ret == 0 && len != 0 ? -1 : ret;
+ len = strlen(s);
+ if ((int)len < 0 || (unsigned)len != len) {
+ gz_error(state, Z_STREAM_ERROR, "string length does not fit in int");
+ return -1;
+ }
+ put = gz_write(state, s, len);
+ return put < len ? -1 : (int)len;
}
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
#include <stdarg.h>
@@ -440,9 +452,9 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
left = strm->avail_in - state->size;
strm->avail_in = state->size;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return state->err;
- memcpy(state->in, state->in + state->size, left);
+ memmove(state->in, state->in + state->size, left);
strm->next_in = state->in;
strm->avail_in = left;
}
return len;
@@ -539,9 +551,9 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
left = strm->avail_in - state->size;
strm->avail_in = state->size;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return state->err;
- memcpy(state->in, state->in + state->size, left);
+ memmove(state->in, state->in + state->size, left);
strm->next_in = state->in;
strm->avail_in = left;
}
return (int)len;