Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Problem width file larger 36K

Closed / Fixed3603553fffffffffffffffffffffffffffffffffCreated 14 years agoUpdated 14 years ago
Descriptionplain2013-02-06 13:12:52
This small program fails on baddocument.odt (in attach)
using gunzip on gz created says -> gzip: baddocument.odt.gz: invalid compressed data--format violated
while for gooddocument.odt (in attach) there are no problems.

proc zip_file {path file} {
set fin [open $path/$file rb]
set fout [open $path/$file.gz wb]
set fzip [zlib push gzip $fout]
while {![eof $fin]} {
puts -nonewline $fzip [read $fin 10]
}
chan pop $fout
close $fin
close $fout
}

zip_file . baddocument.odt
zip_file . gooddocument.odt
vampieraplain2013-02-06 20:12:53
File Added - 460198: baddocument.odt
vampieraplain2013-02-06 20:14:25
File Added - 460199: gooddocument.odt
dkfplain2013-02-06 21:49:55
Just for my understanding, aren't .odt files already compressed? I thought they were variations on the ZIP format.
vampieraplain2013-02-06 21:59:46
yes .odt files  are zip files
I have the same effect with pdf. The example is .odt because it is easy to me edit and change document size.
dkfplain2013-02-06 22:01:37
Yeah, PDFs are also compressed (but in a different way). :-)

I'm wondering whether the problem is to do with incompressible data over a certain size. Don't know if that's the case yet; just speculating for now.
vampieraplain2013-02-06 22:23:30
Maybe. In attach a txt file greater 36K (also in gz format)
It works.
vampieraplain2013-02-06 22:24:01
File Added - 460209: promessisposi.txt
dkfplain2013-02-06 22:29:34
Another possibility for the failure might be failing to flush the data correctly before the core of the [chan pop] is done. (That would show up as a truncation.)

Interesting that the *resulting* data has a minimum size for the problem to occur. That's got to be important.

Just checking, this is the Tcl 8.6.0 release that has the bug? Not one of the betas? I know that there were flushing bugs in the betas.
vampieraplain2013-02-06 22:41:49
Dimension ... in attach a txt file with problem.

my release:
base-tcl-thread 8.6.0.0.296563 linux-glibc2.3-x86_64 from ActiveState
vampieraplain2013-02-06 22:42:12
File Added - 460210: promessisposi256.txt
dkfplain2013-02-10 22:17:01
Confirmed that there's a problem. Switching to using [fcopy] and tinkering with simple [flush] use doesn't affect that.

:-(
dkfplain2013-02-11 16:15:16
allow_comments - 1

OK, this one is evil. The problem is that if, when *not* flushing, the buffer inside zlib itself (32kB) fills up, it asks for Tk to write that buffer out (in 8kB chunks), yet Tk was getting that wrong and not writing anything at all! Only data written at a flushing point, or when the channel was being closed, was getting correctly through. Thus, any attempt to write data that was larger than 32kB *after* compression would fail unless extensive effort was made to force flushes. Ouch.

Doubly embarrassing was that this was a one-line fix. The real bug was that the condition on code to do the writes was comparing the number of free bytes in the buffer (with zero) instead of the number of bytes to write (with zero). Duh!

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

Attachments: