summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2017-04-27 10:43:32 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2017-04-27 10:43:32 (GMT)
commitada887f2ef7727135a81639bc1fd6513ef6c8f43 (patch)
tree4224a3ad4f5a191a02fc1e46101b214d87107adf
parentfa02e7f947236f2d780798ba13956209e355036e (diff)
parent1aa76f11131f03e095b8df149e4f8ba406c88cde (diff)
downloadtcl-ada887f2ef7727135a81639bc1fd6513ef6c8f43.zip
tcl-ada887f2ef7727135a81639bc1fd6513ef6c8f43.tar.gz
tcl-ada887f2ef7727135a81639bc1fd6513ef6c8f43.tar.bz2
[50750c735a] Fix broken test and stop reading uninit-but-allocated memory in zlib channel transform.
-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