summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2017-04-25 19:32:46 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2017-04-25 19:32:46 (GMT)
commit1aa76f11131f03e095b8df149e4f8ba406c88cde (patch)
tree4224a3ad4f5a191a02fc1e46101b214d87107adf
parentfa02e7f947236f2d780798ba13956209e355036e (diff)
downloadtcl-1aa76f11131f03e095b8df149e4f8ba406c88cde.zip
tcl-1aa76f11131f03e095b8df149e4f8ba406c88cde.tar.gz
tcl-1aa76f11131f03e095b8df149e4f8ba406c88cde.tar.bz2
[50750c735a] Fix for uninit memory handling issue in zlib transforms.bug_50750c735a
-rw-r--r--generic/tclZlib.c34
-rw-r--r--tests/zlib.test2
2 files changed, 17 insertions, 19 deletions
diff --git a/generic/tclZlib.c b/generic/tclZlib.c
index 82486d2..fc20d7e 100644
--- a/generic/tclZlib.c
+++ b/generic/tclZlib.c
@@ -3113,30 +3113,28 @@ ZlibTransformOutput(
errorCodePtr);
}
+ /*
+ * No zero-length writes. Flushes must be explicit.
+ */
+
+ if (toWrite == 0) {
+ return 0;
+ }
+
cd->outStream.next_in = (Bytef *) buf;
cd->outStream.avail_in = toWrite;
- do {
+ while (cd->outStream.avail_in > 0) {
e = Deflate(&cd->outStream, cd->outBuffer, cd->outAllocated,
Z_NO_FLUSH, &produced);
+ if (e != Z_OK || produced == 0) {
+ break;
+ }
- if ((e == Z_OK && produced > 0) || e == Z_BUF_ERROR) {
- /*
- * deflate() indicates that it is out of space by returning
- * Z_BUF_ERROR *or* by simply returning Z_OK with no remaining
- * space; in either case, we must write the whole buffer out and
- * retry to compress what is left.
- */
-
- if (e == Z_BUF_ERROR) {
- produced = cd->outAllocated;
- e = Z_OK;
- }
- if (Tcl_WriteRaw(cd->parent, cd->outBuffer, produced) < 0) {
- *errorCodePtr = Tcl_GetErrno();
- return -1;
- }
+ if (Tcl_WriteRaw(cd->parent, cd->outBuffer, produced) < 0) {
+ *errorCodePtr = Tcl_GetErrno();
+ return -1;
}
- } while (e == Z_OK && produced > 0 && cd->outStream.avail_in > 0);
+ }
if (e == Z_OK) {
return toWrite - cd->outStream.avail_in;
diff --git a/tests/zlib.test b/tests/zlib.test
index 9f06eb1..c2f7825 100644
--- a/tests/zlib.test
+++ b/tests/zlib.test
@@ -1004,7 +1004,7 @@ test zlib-12.2 {Patrick Dunnigan's issue} -constraints zlib -setup {
} -cleanup {
removeFile $filesrc
removeFile $filedst
-} -result 4152
+} -result 56
::tcltest::cleanupTests
return