Check-in [c0cb33bec5]
Overview
SHA1:c0cb33bec5f5c5ce142d0d79a6fd9a7f691bd1e8
Date: 2010-09-28 21:52:33
User: rkeene
Edited Comment: Fixed issue with vfs::zip opening zip files smaller than 512b, fixes issue [0c5bcad642]
Original Comment: Fixed issue with vfs::zip opening zip files smaller than 512b
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
References
2010-09-28
22:28 • Ticket [0c5bcad642] vfs::zip fails with zip files smaller than 512 bytes status still Open with 3 other changes (user: rkeene) [details]
Tags And Properties
Context
2010-09-28
22:03
[de59e55104] Added regression suite tests for small zip files (user: rkeene, tags: trunk)
21:52
[c0cb33bec5] Fixed issue with vfs::zip opening zip files smaller than 512b, fixes issue [0c5bcad642] (user: rkeene, tags: trunk)
2010-09-27
22:17
[8f84374b32] Updated to only consider checkins for change revision (user: rkeene, tags: trunk)
Changes

Modified kitsh/buildsrc/kitsh-0.0/zipvfs.tcl from [f8be70e066] to [8fe7ed4f05].

349
350
351
352
353
354
355





356
357
358
359
360
361
362
363
...
364
365
366
367
368
369
370
371




372
373
374
375
376
377
378
	    #           ; # a buffer boundary, nor the header itself
	} else {
	    break
	}
    }

    set hdr [string range $hdr [expr $pos + 4] [expr $pos + 21]]





    set pos [expr [tell $fd] + $pos - 512]

    binary scan $hdr ssssiis \
	cb(ndisk) cb(cdisk) \
	cb(nitems) cb(ntotal) \
	cb(csize) cb(coff) \
	cb(comment)

................................................................................
    set cb(ndisk)	[u_short $cb(ndisk)]
    set cb(nitems)	[u_short $cb(nitems)]
    set cb(ntotal)	[u_short $cb(ntotal)]
    set cb(comment)	[u_short $cb(comment)]

    # Compute base for situations where ZIP file
    # has been appended to another media (e.g. EXE)
    set cb(base)	[expr { $pos - $cb(csize) - $cb(coff) }]




}

proc zip::TOC {fd arr} {
    upvar #0 zip::$fd cb
    upvar 1 $arr sb

    set buf [read $fd 46]







>
>
>
>
>
|







 







|
>
>
>
>







349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
...
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
	    #           ; # a buffer boundary, nor the header itself
	} else {
	    break
	}
    }

    set hdr [string range $hdr [expr $pos + 4] [expr $pos + 21]]

    set seekstart [expr {[tell $fd] - 512}]
    if {$seekstart < 0} {
        set seekstart 0
    }
    set pos [expr {$seekstart + $pos}]

    binary scan $hdr ssssiis \
	cb(ndisk) cb(cdisk) \
	cb(nitems) cb(ntotal) \
	cb(csize) cb(coff) \
	cb(comment)

................................................................................
    set cb(ndisk)	[u_short $cb(ndisk)]
    set cb(nitems)	[u_short $cb(nitems)]
    set cb(ntotal)	[u_short $cb(ntotal)]
    set cb(comment)	[u_short $cb(comment)]

    # Compute base for situations where ZIP file
    # has been appended to another media (e.g. EXE)
    set base            [expr { $pos - $cb(csize) - $cb(coff) }]
    if {$base < 0} {
        set base 0
    }
    set cb(base)	$base
}

proc zip::TOC {fd arr} {
    upvar #0 zip::$fd cb
    upvar 1 $arr sb

    set buf [read $fd 46]

Modified tclvfs/patches/all/tclvfs-20080503-zipvfs.diff from [9b98f84953] to [b70e607501].

1
2
3
4
5
6
7
8
9
10
..
40
41
42
43
44
45
46
47























48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
diff -uNr tclvfs-20080503.orig/library/zipvfs.tcl tclvfs-20080503-3rsk/library/zipvfs.tcl
--- tclvfs-20080503.orig/library/zipvfs.tcl	2008-04-15 16:11:53.000000000 -0500
+++ tclvfs-20080503-3rsk/library/zipvfs.tcl	2010-09-19 03:37:33.000000000 -0500
@@ -107,6 +107,10 @@
 	    
 	    ::zip::stat $zipfd $name sb
 
+            if {$sb(ino) == -1} {
+                vfs::filesystem posixerror $::vfs::posix(EISDIR)
+            }
................................................................................
-	# Only mday can be wrong, at end of month
-	incr mday -1
     }
+
     return $res
 }
 
@@ -400,6 +404,7 @@























 }
 
 proc zip::TOC {fd arr} {
+    upvar #0 zip::$fd cb
     upvar 1 $arr sb
 
     set buf [read $fd 46]
@@ -410,6 +415,8 @@
       flen elen clen sb(disk) sb(attr) \
       sb(atx) sb(ino)
 
+    set sb(ino) [expr {$cb(base) + $sb(ino)}]
+
     if { ![string equal "PK\01\02" $hdr] } {
 	binary scan $hdr H* x
 	error "bad central header: $x"
@@ -442,7 +449,7 @@
 	
 	zip::EndOfArchive $fd cb
 
-	seek $fd $cb(coff) start
+	seek $fd [expr {$cb(base) + $cb(coff)}] start
 
 	set toc(_) 0; unset toc(_); #MakeArray
 	
|

|







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







|








|








1
2
3
4
5
6
7
8
9
10
..
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
diff -uNr tclvfs-20080503.orig/library/zipvfs.tcl tclvfs-20080503-1rsk/library/zipvfs.tcl
--- tclvfs-20080503.orig/library/zipvfs.tcl	2008-04-15 16:11:53.000000000 -0500
+++ tclvfs-20080503-1rsk/library/zipvfs.tcl	2010-09-28 16:43:12.000000000 -0500
@@ -107,6 +107,10 @@
 	    
 	    ::zip::stat $zipfd $name sb
 
+            if {$sb(ino) == -1} {
+                vfs::filesystem posixerror $::vfs::posix(EISDIR)
+            }
................................................................................
-	# Only mday can be wrong, at end of month
-	incr mday -1
     }
+
     return $res
 }
 
@@ -381,7 +385,12 @@
     }
 
     set hdr [string range $hdr [expr $pos + 4] [expr $pos + 21]]
-    set pos [expr [tell $fd] + $pos - 512]
+
+    set seekstart [expr {[tell $fd] - 512}]
+    if {$seekstart < 0} {
+        set seekstart 0
+    }
+    set pos [expr {$seekstart + $pos}]
 
     binary scan $hdr ssssiis \
 	cb(ndisk) cb(cdisk) \
@@ -396,10 +405,15 @@
 
     # Compute base for situations where ZIP file
     # has been appended to another media (e.g. EXE)
-    set cb(base)	[expr { $pos - $cb(csize) - $cb(coff) }]
+    set base            [expr { $pos - $cb(csize) - $cb(coff) }]
+    if {$base < 0} {
+        set base 0
+    }
+    set cb(base)	$base
 }
 
 proc zip::TOC {fd arr} {
+    upvar #0 zip::$fd cb
     upvar 1 $arr sb
 
     set buf [read $fd 46]
@@ -410,6 +424,8 @@
       flen elen clen sb(disk) sb(attr) \
       sb(atx) sb(ino)
 
+    set sb(ino) [expr {$cb(base) + $sb(ino)}]
+
     if { ![string equal "PK\01\02" $hdr] } {
 	binary scan $hdr H* x
 	error "bad central header: $x"
@@ -442,7 +458,7 @@
 	
 	zip::EndOfArchive $fd cb
 
-	seek $fd $cb(coff) start
+	seek $fd [expr {$cb(base) + $cb(coff)}] start
 
 	set toc(_) 0; unset toc(_); #MakeArray