From 14cb7aed9a31de283eb7598956343bf2f943955a Mon Sep 17 00:00:00 2001 From: Vince Darley Date: Tue, 29 Jun 2004 12:47:00 +0000 Subject: [PATCH] fix to zipvfs --- ChangeLog | 5 +++++ library/zipvfs.tcl | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index e3e31aa..caa981e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-06-29 Vince Darley + + * library/zipvfs.tcl: fix to bug finding zip header (reported on + Tcl'ers wiki). + 2004-06-09 Jeff Hobbs * Makefile.in: corrected targets that use 'for' over what may be diff --git a/library/zipvfs.tcl b/library/zipvfs.tcl index 253c442..13a98d3 100644 --- a/library/zipvfs.tcl +++ b/library/zipvfs.tcl @@ -328,19 +328,20 @@ proc zip::Data {fd arr {varPtr ""} {verify 0}} { proc zip::EndOfArchive {fd arr} { upvar 1 $arr cb - seek $fd -22 end - set pos [tell $fd] - set hdr [read $fd 22] + seek $fd -512 end + set hdr [read $fd 512] + set pos [string first "PK\05\06" $hdr] + if {$pos == -1} { + error "no header found" + } + set hdr [string range $hdr [expr $pos + 4] [expr $pos + 21]] + set pos [expr [tell $fd] + $pos - 512] - binary scan $hdr A4ssssiis xhdr \ + binary scan $hdr ssssiis \ cb(ndisk) cb(cdisk) \ cb(nitems) cb(ntotal) \ cb(csize) cb(coff) \ - cb(comment) - - if { ![string equal "PK\05\06" $xhdr]} { - error "bad header" - } + cb(comment) set cb(ndisk) [u_short $cb(ndisk)] set cb(nitems) [u_short $cb(nitems)] -- 2.23.0