Tcl Source Code

View Ticket
Login
Ticket UUID: 3390073
Title: Bug in zlib command in 8.6b2
Type: Bug Version: obsolete: 8.6b2
Submitter: rich123 Created on: 2011-08-11 14:36:05
Subsystem: 18. Commands M-Z Assigned To: dkf
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2011-08-12 17:01:45
Resolution: Fixed Closed By: dkf
    Closed on: 2011-08-12 10:01:45
Description:
Performing the example at the top of http://wiki.tcl.tk/4610 for generating a gzip file with 8.6b2 fails:

% set file critcl.kit 
critcl.kit
% set fin [open $file rb]
file5
% set header [dict create \
        filename $file time [file mtime $file] comment "Created by Tcl[info patchlevel]"]
filename critcl.kit time 1313070437 comment {Created by Tcl8.6b2}
% set fout [zlib push gzip [open $file.gz wb] -header $header]
file6
% fcopy $fin $fout
161266
% close $fin
% close $fout
% exit
rellis@d820:~/downloads/tcl86b2/inst/usr/local/bin$ gunzip -tv critcl.kit.gz 
critcl.kit.gz:
gzip: critcl.kit.gz: invalid compressed data--format violated

8.6b2 was compiled for, and running under, Slackware 13.1 64-bit.  GCC version is 4.4.4.
User Comments: dkf added on 2011-08-12 17:01:45:

allow_comments - 1

Was completely broken, but a one-line fix (was returning the wrong length of written data from the transform guts). Note that _all_ compressing transforms were broken. Fixed in trunk tip.

Workaround is to read the binary data in and compress with [zlib gzip] *or* use the [zlib stream gzip] to make a compressing stream (so you can process the data a bit at a time). [substitute gzip with compress or deflate if you prefer]

rich123 added on 2011-08-12 08:31:38:

File Added - 420930: testgzip.tcl

rich123 added on 2011-08-12 08:29:59:
I also have to retract my report re. 32-bit linux.  The 32-bit system exhibits identical behavior to the 64-bit system on the test script.

rich123 added on 2011-08-12 08:25:59:
Following up on the posting to comp.lang.tcl "zlib push creates corrupt file gz file when source size is equal or greater than 8092" this test script:

puts "Tcl[ info patchlevel ]"

set zeros [ open /dev/zero {RDONLY BINARY} ]

foreach size {8191 8192} {
  set data [ read $zeros $size ] 

  set fout [ open $size {WRONLY CREAT BINARY} ]
  puts -nonewline $fout $data
  close $fout

  set fin [open $size rb]
  set header [dict create filename $size time [file mtime $size] comment "Created by Tcl[info patchlevel]"]
  set fout [zlib push gzip [open $size.gz wb] -header $header]
  fcopy $fin $fout
  close $fin
  close $fout

}

close $zeros

Produces this result on 64-bit Linux - GCC 4.4.4:

rellis@d820:~/downloads/tcl86b2/inst/usr/local/bin$ ./tclsh8.6 testgzip.tcl 
Tcl8.6b2
rellis@d820:~/downloads/tcl86b2/inst/usr/local/bin$ gunzip -tv *gz
8191.gz:         OK
8192.gz:
gzip: 8192.gz: invalid compressed data--format violated

And produces these resulting files:
 8 -rw-r--r-- 1 rellis 8191 2011-08-11 21:22 8191
 4 -rw-r--r-- 1 rellis     72 2011-08-11 21:22 8191.gz
 8 -rw-r--r-- 1 rellis 8192 2011-08-11 21:22 8192
 8 -rw-r--r-- 1 rellis 4159 2011-08-11 21:22 8192.gz

rich123 added on 2011-08-12 01:18:49:
Another data point:

The example from http://wiki.tcl.tk/4610 using 8.6b2 produces a proper gzip file on 32-bit Linux compiled with GCC 4.2.4.

rich123 added on 2011-08-12 00:53:54:
Another test to narrow down the culprit:

% set file critcl.kit
critcl.kit
% set fin [open $file rb]  
file5
% set header [dict create filename $file time [file mtime $file] comment "Created by Tcl[info patchlevel]"]
filename critcl.kit time 1313079102 comment {Created by Tcl8.6b2}
% set fout [open $file.gz wb]
file6
% set comp [ zlib gzip $data -header $header ] ; list
% puts -nonewline $fout $comp
% close $fin
% close $fout
% exit
rellis@d820:~/downloads/tcl86b2/inst/usr/local/bin$ gunzip -tv critcl.kit.gz 
critcl.kit.gz:   OK

Not using zlib push gzip produces a correct gzip file.

Attachments: