Skip to content
Tcl Source Code View Ticket
Login

View Ticket

zlib deflate streaming raises error in case of zero length input

Closed / Fixed25842c161fd621d8d111430a3637688f55aeaa94Created 11 years agoUpdated 10 years ago
Descriptionplain2016-02-03 14:56:29
This two line script

set zlib [zlib stream deflate]
$zlib put ""

raises error "buffer error".

At least, the documentation should say, that the cmd raises this error, if feeded with zero length input, if this is in fact the desired behaviour.

I'd say, that should do nothing, gracefully.
Referenced by3
  • 6b926caddb[25842c161f] Ensure that finalization of a zlib stream works. check-in2017-02-26 15:33:04
  • 23af13880c[25842c161f] Ensure that finalization of a zlib stream works. check-in2017-02-26 15:32:11
  • be8c38b974zlib stream finalize calls deflate with no input - this case (and this case only) must be allowed. Fixes 2nd issue in [25842c161f], introduced by [c1aff52ef3] check-in2017-02-11 05:06:43
pointsmanplain2016-02-03 15:03:37
Futher note:

set zlib [zlib stream deflate]
$zlib get

does nothing, gracefully.
dkfhtml2016-02-03 15:30:59

Code was excessively smartass. Made simpler and added a specific step to stop this foolishness.

aspectplain2016-09-03 08:44:05
This patch has broken finalizing streams with [$zlib put -finalize ""] or [zlib finalize]:

package require zlib

set t1 [
    set c [zlib stream gzip]
    $c put abcdeEDCBA..
    $c finalize
    $c get
]
set t2 [
    set c [zlib stream gzip]
    $c put -finalize abcdeEDCBA..
    $c get
]
puts [expr {$t1 eq $t2}]
# => 0

Here $t2 is the correct stream, but $t1 is truncated.
apnadkarniplain2016-11-21 16:36:34
Marked as open as I also ran into the the brokenness logged by aspect in the previous comment. The issue seems to be tclZlib.c line 1210: 

if (size == 0) { return TCL_OK; }

Since finalize calls with zero length data that line returns.
aspectplain2017-02-11 05:09:58
Added test and fix in [bug-25842c161f].

The API feels fragile with all these changes going on, but that's largely (as dkf observes) due to zlib's weird rules not mapping well to what Tcl wants from a channel layer.
dkfhtml2017-02-26 15:34:55

Branch committed to main release branches; thanks for the test cases (which I tweaked so that they were a little less mysterious when they failed).

Log in (anonymous is fine) to add a comment.