From 466db95da7d18bfdbf02707fbd23fc9c7926447f Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Thu, 21 Sep 2023 10:59:57 +0000 Subject: Disable zipfs password tests for macos. Unix, Windows pass. See [bbe7c6ff9e] --- tests/zipfs.test | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/tests/zipfs.test b/tests/zipfs.test index 1a521dc..3471d63 100644 --- a/tests/zipfs.test +++ b/tests/zipfs.test @@ -18,6 +18,7 @@ source [file join [file dirname [info script]] tcltests.tcl] testConstraint zipfs [expr {[llength [info commands zipfs]]}] testConstraint zipfslib 1 + set ziproot [zipfs root] set CWD [pwd] @@ -574,20 +575,6 @@ namespace eval test_ns_zipfs { cleanup } -result {1 {decryption failed} 1} - test zipfs-mount-password-4 "mount - verify uncompressed cipher readable with password" -body { - zipfs mount [zippath test-password.zip] $defaultMountPoint password - readbin [file join $defaultMountPoint cipher.bin] - } -cleanup { - cleanup - } -result ciphertext - - test zipfs-mount-password-5 "mount - verify compressed cipher readable with password" -body { - zipfs mount [zippath test-password.zip] $defaultMountPoint password - readbin [file join $defaultMountPoint cipher-deflate.bin] - } -cleanup { - cleanup - } -result [lseq 100] - test zipfs-mount-nested-1 "mount - nested mount on non-existing path" -setup { mount [zippath test.zip] } -cleanup { @@ -973,13 +960,17 @@ namespace eval test_ns_zipfs { gets $fd } -result $result {*}$args } + if {$::tcl_platform(platform) in {windows unix}} { + # The bug bbe7c6ff9e only manifests on macos + testConstraint bbe7c6ff9e 1 + } testpassword plain plain.txt password plaintext testpassword plain-nopassword plain.txt "" plaintext testpassword plain-badpassword plain.txt xxx plaintext - testpassword cipher cipher.bin password ciphertext + testpassword cipher cipher.bin password ciphertext -constraints bbe7c6ff9e testpassword cipher-nopassword cipher.bin {} "decryption failed" -returnCodes error testpassword cipher-badpassword cipher.bin xxx "invalid CRC" -returnCodes error - testpassword cipher-deflate cipher-deflate.bin password [lseq 100] + testpassword cipher-deflate cipher-deflate.bin password [lseq 100] -constraints bbe7c6ff9e testpassword cipher-deflate-nopassword cipher-deflate.bin {} "decryption failed" -returnCodes error testpassword cipher-deflate-badpassword cipher-deflate.bin xxx "decompression error" -returnCodes error -- cgit v0.12 From 7a2afa0583f4f4679beb7e73bfa63c47efc00aeb Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 21 Sep 2023 11:04:01 +0000 Subject: Fix [e368ba6683]: ThreadSafeLocalTime(): check if localtime_r() encountered error --- generic/tclClock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/tclClock.c b/generic/tclClock.c index 194cfb3..ecf5913 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -1714,7 +1714,7 @@ ThreadSafeLocalTime( struct tm *tmPtr = (struct tm *)Tcl_GetThreadData(&tmKey, sizeof(struct tm)); #ifdef HAVE_LOCALTIME_R - localtime_r(timePtr, tmPtr); + tmPtr = localtime_r(timePtr, tmPtr); #else struct tm *sysTmPtr; -- cgit v0.12 From 5236d11a8865a2e51fe97abfadea3a0d6b2a7030 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 21 Sep 2023 11:06:57 +0000 Subject: Fix [47902ec47a]: ThreadSafeLocalTime(): remove redundant localtime() call --- generic/tclClock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/tclClock.c b/generic/tclClock.c index ecf5913..38c4ec0 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -1724,7 +1724,7 @@ ThreadSafeLocalTime( Tcl_MutexUnlock(&clockMutex); return NULL; } - memcpy(tmPtr, localtime(timePtr), sizeof(struct tm)); + memcpy(tmPtr, sysTmPtr, sizeof(struct tm)); Tcl_MutexUnlock(&clockMutex); #endif return tmPtr; -- cgit v0.12 From 8c63cf83ec217d6dad91da1b16b7357bbc512860 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 21 Sep 2023 11:10:34 +0000 Subject: Fix testcase for [00655c867e] (making it independent from timezone) --- tests/clock.test | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/clock.test b/tests/clock.test index 4b12d5c..98a065e 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -18605,10 +18605,10 @@ test clock-7.10 {Julian Day, negative amount} { # add negative amounts to Julian day 0 instead set s0 [clock scan 0 -format %J -gmt true] set J0 [scan [clock format $s0 -format %J -gmt true] %lld] - set s0m1d [clock add $s0 -1 days] - set s0m24h [clock add $s0 -24 hours] + set s0m1d [clock add $s0 -1 days -timezone :UTC] + set s0m24h [clock add $s0 -24 hours -timezone :UTC] set J0m24h [scan [clock format $s0m24h -format %J -gmt true] %lld] - set s0m1s [clock add $s0 -1 seconds] + set s0m1s [clock add $s0 -1 seconds -timezone :UTC] set J0m1s [scan [clock format $s0m1s -format %J -gmt true] %lld] list $s0m1d $s0m24h $J0m24h $s0m1s $J0m1s $s0 $J0 \ [::tcl::mathop::== $s0m1d $s0m24h] [::tcl::mathop::== $J0m24h $J0m1s] -- cgit v0.12 From ed32508df0f991dc79ed6d0af0abe085f3686923 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 21 Sep 2023 12:19:24 +0000 Subject: Fix [dd54ac5323]: fileSystem.test: Set moreThanOneDrive constraint correctly --- tests/fileSystem.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fileSystem.test b/tests/fileSystem.test index 1e6045b..f825e2b 100644 --- a/tests/fileSystem.test +++ b/tests/fileSystem.test @@ -70,7 +70,7 @@ apply {{} { lappend drives $vol } } - testConstraint moreThanOneDrive [llength $drives] + testConstraint moreThanOneDrive [expr {[llength $drives] > 1}] } finally { cd $dir } -- cgit v0.12 From fffc4119bef3f1894ff2043a720b902b6a88adbe Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Fri, 22 Sep 2023 13:56:35 +0000 Subject: Bug [0aaeb9c380]. Fix spurious tcltest output on hyphenated constraints --- library/tcltest/tcltest.tcl | 1 + 1 file changed, 1 insertion(+) diff --git a/library/tcltest/tcltest.tcl b/library/tcltest/tcltest.tcl index 984f5c1..d3e9ea4 100644 --- a/library/tcltest/tcltest.tcl +++ b/library/tcltest/tcltest.tcl @@ -2365,6 +2365,7 @@ proc tcltest::Skipped {name constraints} { # make sure that the constraints are satisfied. set doTest 0 + set constraints [string trim $constraints] if {[string match {*[$\[]*} $constraints] != 0} { # full expression, e.g. {$foo > [info tclversion]} catch {set doTest [uplevel #0 [list expr $constraints]]} -- cgit v0.12 From cee706d627cadc060d6fd1ab4fc5044e26d2034c Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 22 Sep 2023 15:01:00 +0000 Subject: Fix test contraint "bbe7c6ff9e" --- tests/zipfs.test | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/zipfs.test b/tests/zipfs.test index 3471d63..5d20084 100644 --- a/tests/zipfs.test +++ b/tests/zipfs.test @@ -960,10 +960,8 @@ namespace eval test_ns_zipfs { gets $fd } -result $result {*}$args } - if {$::tcl_platform(platform) in {windows unix}} { - # The bug bbe7c6ff9e only manifests on macos - testConstraint bbe7c6ff9e 1 - } + # The bug bbe7c6ff9e only manifests on macos + testConstraint bbe7c6ff9e [expr {$::tcl_platform(os) ne "Darwin"}] testpassword plain plain.txt password plaintext testpassword plain-nopassword plain.txt "" plaintext testpassword plain-badpassword plain.txt xxx plaintext -- cgit v0.12 From e7bd5573df5961237ca1c08952aee3c2493e3eb5 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Sat, 23 Sep 2023 13:36:10 +0000 Subject: Bug [4645658689] - zipfs file truncation with open r+ --- generic/tclZipfs.c | 65 +++++++++++++++++++++++-------------- tests/zipfs.test | 95 +++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 107 insertions(+), 53 deletions(-) diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index 45a2041..b0dbd7d 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -4628,18 +4628,16 @@ InitWritableChannel( */ info->numBytes = 0; + z->crc32 = 0; /* Truncated, CRC no longer applicable */ } else if (z->data) { /* * Already got uncompressed data. */ + if (z->numBytes > info->maxWrite) + goto tooBigError; - unsigned int j = z->numBytes; - - if (j > info->maxWrite) { - j = info->maxWrite; - } - memcpy(info->ubuf, z->data, j); - info->numBytes = j; + memcpy(info->ubuf, z->data, z->numBytes); + info->numBytes = z->numBytes; } else { /* * Need to uncompress the existing data. @@ -4697,39 +4695,53 @@ InitWritableChannel( } err = inflate(&stream, Z_SYNC_FLUSH); inflateEnd(&stream); - if ((err == Z_STREAM_END) - || ((err == Z_OK) && (stream.avail_in == 0))) { - if (cbuf) { - memset(info->keys, 0, sizeof(info->keys)); - ckfree(cbuf); - } - return TCL_OK; + if ((err != Z_STREAM_END) && + ((err != Z_OK) || (stream.avail_in != 0))) { + goto corruptionError; + } + /* Even if decompression succeeded, counts should be as expected */ + if (stream.total_out != z->numBytes) + goto corruptionError; + info->numBytes = z->numBytes; + if (cbuf) { + ckfree(cbuf); } - goto corruptionError; } else if (z->isEncrypted) { /* * Need to decrypt some otherwise-simple stored data. */ - - for (i = 0; i < z->numBytes - 12; i++) { + if (z->numCompressedBytes <= 12 || + (z->numCompressedBytes - 12) != z->numBytes) + goto corruptionError; + int len = z->numCompressedBytes - 12; + for (i = 0; i < len; i++) { ch = zbuf[i]; info->ubuf[i] = zdecode(info->keys, crc32tab, ch); } - } else { + info->numBytes = len; + } + else { /* * Simple stored data. Copy into our working buffer. */ - memcpy(info->ubuf, zbuf, z->numBytes); + info->numBytes = z->numBytes; } memset(info->keys, 0, sizeof(info->keys)); } + + assert(info->numBytes == 0 || info->numBytes == z->numBytes); return TCL_OK; memoryError: ZIPFS_MEM_ERROR(interp); goto error_cleanup; + tooBigError: + ZIPFS_ERROR(interp, "file size exceeds max writable"); + ZIPFS_ERROR_CODE(interp, "TOOBIG"); + goto error_cleanup; + corruptionError: if (cbuf) { memset(info->keys, 0, sizeof(info->keys)); @@ -4857,6 +4869,9 @@ InitReadableChannel( && ((err != Z_OK) || (stream.avail_in != 0))) { goto corruptionError; } + /* Even if decompression succeeded, counts should be as expected */ + if (stream.total_out != z->numBytes) + goto corruptionError; if (ubuf) { info->isEncrypted = 0; @@ -4871,7 +4886,8 @@ InitReadableChannel( * Decode encrypted but uncompressed file, since we support Tcl_Seek() * on it, and it can be randomly accessed later. */ - + if (z->numCompressedBytes <= 12 || (z->numCompressedBytes - 12) != z->numBytes) + goto corruptionError; len = z->numCompressedBytes - 12; ubuf = (unsigned char *) attemptckalloc(len); if (ubuf == NULL) { @@ -5011,14 +5027,14 @@ ZipFSOpenFileChannelProc( int mode, TCL_UNUSED(int) /* permissions */) { - int trunc = (mode & O_TRUNC) != 0; - int wr = (mode & (O_WRONLY | O_RDWR)) != 0; - pathPtr = Tcl_FSGetNormalizedPath(NULL, pathPtr); if (!pathPtr) { return NULL; } + int trunc = (mode & O_TRUNC) != 0; + int wr = (mode & (O_WRONLY | O_RDWR)) != 0; + /* * Check for unsupported modes. */ @@ -5027,7 +5043,8 @@ ZipFSOpenFileChannelProc( Tcl_SetErrno(EACCES); if (interp) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "write access not supported: %s", + "%s not supported: %s", + mode & O_APPEND ? "append mode" : "write access", Tcl_PosixError(interp))); } return NULL; diff --git a/tests/zipfs.test b/tests/zipfs.test index 5d20084..0275234 100644 --- a/tests/zipfs.test +++ b/tests/zipfs.test @@ -410,6 +410,11 @@ namespace eval test_ns_zipfs { } } + # list of paths -> list of paths under [zipfs root] + proc zipfspaths {args} { + return [lmap path $args {file join [zipfs root] $path}] + } + proc cleanup {} { dict for {mount -} [zipfs mount] { if {[string match //zipfs:/test* $mount]} { @@ -701,6 +706,7 @@ namespace eval test_ns_zipfs { testzipfslist no-pattern-mount-on-empty "" {test.zip {}} {{} test testdir testdir/test2} -constraints !zipfslib testzipfslist no-pattern-mount-on-root "" [list test.zip [zipfs root]] {{} test testdir testdir/test2} -constraints !zipfslib testzipfslist no-pattern-mount-on-slash "" [list test.zip /] {{} test testdir testdir/test2} -constraints !zipfslib + testzipfslist no-pattern-mount-on-level3 "" [list test.zip testmt/a/b] {{} testmt testmt/a testmt/a/b testmt/a/b/test testmt/a/b/testdir testmt/a/b/testdir/test2} -constraints {bug-02acab5aea !zipfslib} testzipfslist no-pattern-multiple "" {test.zip testmountA test.zip testmountB/subdir} { testmountA testmountA/test testmountA/testdir testmountA/testdir/test2 testmountB/subdir testmountB/subdir/test testmountB/subdir/testdir testmountB/subdir/testdir/test2 @@ -723,21 +729,25 @@ namespace eval test_ns_zipfs { testnumargs "zipfs exists" "filename" "" # Generates tests for zipfs exists - proc testzipfsexists {id path result args} { + proc testzipfsexists [list id path result [list mountpoint $defaultMountPoint] args] { test zipfs-exists-$id "zipfs exists $id" -body { zipfs exists $path } -setup { - mount [zippath test.zip] + mount [zippath test.zip] $mountpoint } -cleanup { + zipfs unmount $mountpoint cleanup } -result $result {*}$args } - testzipfsexists native-file [info nameofexecutable] 0 + testzipfsexists native-file [info nameofexecutable] 0 testzipfsexists nonexistent-file [file join $defaultMountPoint nosuchfile] 0 - testzipfsexists file [file join $defaultMountPoint test] 1 - testzipfsexists dir [file join $defaultMountPoint testdir] 1 - testzipfsexists mountpoint $defaultMountPoint 1 - testzipfsexists root [zipfs root] 1 -constraints bug-02acab5aea + testzipfsexists file [file join $defaultMountPoint test] 1 + testzipfsexists dir [file join $defaultMountPoint testdir] 1 + testzipfsexists mountpoint $defaultMountPoint 1 + testzipfsexists root [zipfs root] 1 \ + $defaultMountPoint -constraints bug-02acab5aea + testzipfsexists level3 [file join $defaultMountPoint a b] 1 \ + [file join $defaultMountPoint a b c] -constraints bug-02acab5aea # # zipfs find @@ -779,12 +789,9 @@ namespace eval test_ns_zipfs { test.zip testmountA test.zip testmountB/subdir } {} - variable path testzipfsfind absolute-path [file join [zipfs root] testmountA] { test.zip testmountA test.zip testmountB/subdir - } [lmap path { - testmountA/test testmountA/testdir testmountA/testdir/test2 - } {file join [zipfs root] $path}] + } [zipfspaths testmountA/test testmountA/testdir testmountA/testdir/test2] testzipfsfind relative-path testdir { test.zip testmountA test.zip testmountB/subdir @@ -798,9 +805,17 @@ namespace eval test_ns_zipfs { # bug-6183f535c8 testzipfsfind root-path [zipfs root] { test.zip {} test.zip testmountB/subdir - } [lmap path { - test testdir testdir/test2 - } {file join [zipfs root] $path}] -constraints !zipfslib + } [zipfspaths test testdir testdir/test2] -constraints !zipfslib + + testzipfsfind level3 [file join [zipfs root] testmt a] { + test.zip testmt/a/b + } [zipfspaths testmt/a/b testmt/a/b/test testmt/a/b/testdir testmt/a/b/testdir/test2] \ + -constraints bug-02acab5aea + + testzipfsfind level3-root [zipfs root] { + test.zip testmt/a/b + } [zipfspaths testmt testmt/a testmt/a/b testmt/a/b/test testmt/a/b/testdir testmt/a/b/testdir/test2] \ + -constraints bug-02acab5aea test zipfs-find-native-absolute "zipfs find on native file system" -setup { set dir [makeDirectory zipfs-native-absolute] @@ -830,7 +845,6 @@ namespace eval test_ns_zipfs { zipfs find [file tail $dir] } -result {zipfs-native-relative/subdir zipfs-native-relative/subdir/native} - # # zipfs info testnumargs "zipfs info" "filename" "" @@ -876,6 +890,15 @@ namespace eval test_ns_zipfs { zipfs info $defaultMountPoint } -result [list [zippath junk-at-start.zip] 0 0 4] + test zipfs-info-level3 "zipfs info on mount point - verify correct offset of zip content" -setup { + # zip starts at offset 4 + mount [zippath junk-at-start.zip] /testmt/a/b + } -cleanup { + cleanup + } -body { + zipfs info [file join [zipfs root] testmt a] + } -result {{} 0 0 0} -constraints bug-02acab5aea + # # zipfs canonical - # TODO - semantics are very unclear. Can produce nonsensical paths like @@ -907,14 +930,9 @@ namespace eval test_ns_zipfs { testzipfscanonical backslashes X:\\\\foo\\\\bar [file join [zipfs root] foo bar] -constraints win testzipfscanonical backslashes-1 X:/foo\\\\bar [file join [zipfs root] foo bar] -constraints win - - - # - # TODO - read of zipfs file Bad CRC - # # Read/uncompress - proc testuncompress {id zippath result {filename abac-repeat.txt} args} { + proc testuncompress {id zippath result {filename abac-repeat.txt} {openopts {}} args} { variable defaultMountPoint set zippath [zippath $zippath] test zipfs-uncompress-$id "zipfs uncompress $id" -setup { @@ -927,17 +945,26 @@ namespace eval test_ns_zipfs { } cleanup } -body { - set fd [open [file join $defaultMountPoint $filename]] + set fd [open [file join $defaultMountPoint $filename] {*}$openopts] gets $fd } -result $result {*}$args } + testuncompress stored test.zip test test testuncompress stored teststored.zip aaaaaaaaaaaaaa testuncompress deflate testdeflated2.zip aaaaaaaaaaaaaa - testuncompress deflate-error broken.zip {decompression error} deflatezliberror -returnCodes error - testuncompress bzip2 testbzip2.zip {unsupported compression method} abac-repeat.txt -returnCodes error - testuncompress lzma testfile-lzma.zip {unsupported compression method} abac-repeat.txt -returnCodes error - testuncompress xz testfile-xz.zip {unsupported compression method} abac-repeat.txt -returnCodes error - testuncompress zstd testfile-zstd.zip {unsupported compression method} abac-repeat.txt -returnCodes error + # Test open modes - see bug [4645658689] + testuncompress stored-rw teststored.zip aaaaaaaaaaaaaa abac-repeat.txt r+ + testuncompress deflate-rw testdeflated2.zip aaaaaaaaaaaaaa abac-repeat.txt r+ + testuncompress stored-wr teststored.zip {} abac-repeat.txt w+ -constraints bug-00018ec7a0 + testuncompress deflate-wr testdeflated2.zip {} abac-repeat.txt w+ -constraints bug-00018ec7a0 + testuncompress stored-ar teststored.zip {} abac-repeat.txt a+ + testuncompress deflate-ar testdeflated2.zip {} abac-repeat.txt a+ + + testuncompress deflate-error broken.zip {decompression error} deflatezliberror {} -returnCodes error + testuncompress bzip2 testbzip2.zip {unsupported compression method} abac-repeat.txt {} -returnCodes error + testuncompress lzma testfile-lzma.zip {unsupported compression method} abac-repeat.txt {} -returnCodes error + testuncompress xz testfile-xz.zip {unsupported compression method} abac-repeat.txt {} -returnCodes error + testuncompress zstd testfile-zstd.zip {unsupported compression method} abac-repeat.txt {} -returnCodes error proc testpassword {id filename password result args} { variable defaultMountPoint @@ -1066,12 +1093,22 @@ namespace eval test_ns_zipfs { lsort -stride 2 [file stat [zipfs root]] } -result [fixupstat {atime 0 ctime 0 dev 0 gid 0 ino 0 mode 16749 mtime 0 nlink 0 size 0 type directory uid 0}] - test zipfs-file-stat-root-subdir-mount "Read stat of root when mount is subdir" -setup { + test zipfs-file-stat-root-subdir-mount "Read stat of root when mount is subdir" -constraints { + bug-02acab5aea + } -setup { mount [zippath test.zip] - } -cleanup cleanup -constraints bug-02acab5aea -body { + } -cleanup cleanup -body { lsort -stride 2 [file stat [zipfs root]] } -result [fixupstat {atime 0 ctime 0 dev 0 gid 0 ino 0 mode 16749 mtime 0 nlink 0 size 0 type directory uid 0}] + test zipfs-file-stat-level3 "Stat on a directory that is intermediary in a mount point" -constraints { + bug-02acab5aea + } -setup { + mount [zippath test.zip] [file join $defaultMountPoint mt2] + } -cleanup cleanup -body { + lsort -stride 2 [file stat $defaultMountPoint] + } + # # glob of zipfs file proc testzipfsglob {id mountpoint pat result {globopt {}} args} { -- cgit v0.12 From fa3868a2a6dfe5003e5c2c78f6f2d1a232d767a2 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Sun, 24 Sep 2023 16:35:34 +0000 Subject: More tests for zipfs --- generic/tclZipfs.c | 8 +- tests/zipfs.test | 229 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 210 insertions(+), 27 deletions(-) diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index b0dbd7d..b8a8c09 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -4633,7 +4633,7 @@ InitWritableChannel( /* * Already got uncompressed data. */ - if (z->numBytes > info->maxWrite) + if (z->numBytes > (int) info->maxWrite) goto tooBigError; memcpy(info->ubuf, z->data, z->numBytes); @@ -4700,7 +4700,7 @@ InitWritableChannel( goto corruptionError; } /* Even if decompression succeeded, counts should be as expected */ - if (stream.total_out != z->numBytes) + if ((int) stream.total_out != z->numBytes) goto corruptionError; info->numBytes = z->numBytes; if (cbuf) { @@ -4730,7 +4730,7 @@ InitWritableChannel( memset(info->keys, 0, sizeof(info->keys)); } - assert(info->numBytes == 0 || info->numBytes == z->numBytes); + assert(info->numBytes == 0 || (int) info->numBytes == z->numBytes); return TCL_OK; memoryError: @@ -4870,7 +4870,7 @@ InitReadableChannel( goto corruptionError; } /* Even if decompression succeeded, counts should be as expected */ - if (stream.total_out != z->numBytes) + if ((int) stream.total_out != z->numBytes) goto corruptionError; if (ubuf) { diff --git a/tests/zipfs.test b/tests/zipfs.test index 0275234..200a8a1 100644 --- a/tests/zipfs.test +++ b/tests/zipfs.test @@ -932,14 +932,14 @@ namespace eval test_ns_zipfs { # # Read/uncompress - proc testuncompress {id zippath result {filename abac-repeat.txt} {openopts {}} args} { + proc testzipfsread {id zippath result {filename abac-repeat.txt} {openopts {}} args} { variable defaultMountPoint set zippath [zippath $zippath] - test zipfs-uncompress-$id "zipfs uncompress $id" -setup { + test zipfs-read-$id "zipfs read $id" -setup { unset -nocomplain fd zipfs mount $zippath $defaultMountPoint } -cleanup { - # In case mount succeeded when it should not + # In case open succeeded when it should not if {[info exists fd]} { close $fd } @@ -948,24 +948,207 @@ namespace eval test_ns_zipfs { set fd [open [file join $defaultMountPoint $filename] {*}$openopts] gets $fd } -result $result {*}$args + + set data [readbin $zippath] + test zipfs-read-memory-$id "zipfs read in-memory $id" -setup { + unset -nocomplain fd + zipfs mount_data $data $defaultMountPoint + } -cleanup { + # In case open succeeded when it should not + if {[info exists fd]} { + close $fd + } + cleanup + } -body { + set fd [open [file join $defaultMountPoint $filename] {*}$openopts] + gets $fd + } -result $result {*}$args + } - testuncompress stored test.zip test test - testuncompress stored teststored.zip aaaaaaaaaaaaaa - testuncompress deflate testdeflated2.zip aaaaaaaaaaaaaa + testzipfsread stored test.zip test test + testzipfsread stored teststored.zip aaaaaaaaaaaaaa + testzipfsread deflate testdeflated2.zip aaaaaaaaaaaaaa # Test open modes - see bug [4645658689] - testuncompress stored-rw teststored.zip aaaaaaaaaaaaaa abac-repeat.txt r+ - testuncompress deflate-rw testdeflated2.zip aaaaaaaaaaaaaa abac-repeat.txt r+ - testuncompress stored-wr teststored.zip {} abac-repeat.txt w+ -constraints bug-00018ec7a0 - testuncompress deflate-wr testdeflated2.zip {} abac-repeat.txt w+ -constraints bug-00018ec7a0 - testuncompress stored-ar teststored.zip {} abac-repeat.txt a+ - testuncompress deflate-ar testdeflated2.zip {} abac-repeat.txt a+ - - testuncompress deflate-error broken.zip {decompression error} deflatezliberror {} -returnCodes error - testuncompress bzip2 testbzip2.zip {unsupported compression method} abac-repeat.txt {} -returnCodes error - testuncompress lzma testfile-lzma.zip {unsupported compression method} abac-repeat.txt {} -returnCodes error - testuncompress xz testfile-xz.zip {unsupported compression method} abac-repeat.txt {} -returnCodes error - testuncompress zstd testfile-zstd.zip {unsupported compression method} abac-repeat.txt {} -returnCodes error + testzipfsread stored-rw teststored.zip aaaaaaaaaaaaaa abac-repeat.txt r+ + testzipfsread deflate-rw testdeflated2.zip aaaaaaaaaaaaaa abac-repeat.txt r+ + testzipfsread stored-wr teststored.zip {} abac-repeat.txt w+ -constraints bug-00018ec7a0 + testzipfsread deflate-wr testdeflated2.zip {} abac-repeat.txt w+ -constraints bug-00018ec7a0 + testzipfsread stored-ar teststored.zip {} abac-repeat.txt a+ + testzipfsread deflate-ar testdeflated2.zip {} abac-repeat.txt a+ + + testzipfsread nosuch test.zip "file not found \"//zipfs:/testmount/nosuchfile\": no such file or directory" nosuchfile {} -returnCodes error + testzipfsread deflate-error broken.zip {decompression error} deflatezliberror {} -returnCodes error + testzipfsread bzip2 testbzip2.zip {unsupported compression method} abac-repeat.txt {} -returnCodes error + testzipfsread lzma testfile-lzma.zip {unsupported compression method} abac-repeat.txt {} -returnCodes error + testzipfsread xz testfile-xz.zip {unsupported compression method} abac-repeat.txt {} -returnCodes error + testzipfsread zstd testfile-zstd.zip {unsupported compression method} abac-repeat.txt {} -returnCodes error + + test zipfs-read-unwritable "Writes not allowed on file opened for read" -setup { + mount [zippath test.zip] + } -cleanup { + close $fd + cleanup + } -body { + set fd [open [file join $defaultMountPoint test]] + puts $fd blah + } -result {channel "*" wasn't opened for writing} -match glob -returnCodes error + + # + # Write + proc testzipfswrite {id zippath result filename mode args} { + variable defaultMountPoint + set zippath [zippath $zippath] + set path [file join $defaultMountPoint $filename] + set body { + set fd [open $path $mode] + fconfigure $fd -translation binary + puts -nonewline $fd "xyz" + close $fd + set fd [open $path] + fconfigure $fd -translation binary + read $fd + } + test zipfs-write-$id "zipfs write $id" -setup { + unset -nocomplain fd + zipfs mount $zippath $defaultMountPoint + } -cleanup { + # In case open succeeded when it should not + if {[info exists fd]} { + close $fd + } + cleanup + } -body $body -result $result {*}$args + + set data [readbin $zippath] + test zipfs-write-memory-$id "zipfs write in-memory $id" -setup { + unset -nocomplain fd + zipfs mount_data $data $defaultMountPoint + } -cleanup { + # In case open succeeded when it should not + if {[info exists fd]} { + close $fd + } + cleanup + } -body $body -result $result {*}$args + + } + testzipfswrite create-w test.zip "file not found \"//zipfs:/testmount/newfile\": no such file or directory" newfile w -returnCodes error + testzipfswrite create-wr test.zip "file not found \"//zipfs:/testmount/newfile\": no such file or directory" newfile w+ -returnCodes error + testzipfswrite create-a test.zip "append mode not supported: permission denied" newfile a -returnCodes error + testzipfswrite create-ar test.zip "file not found \"//zipfs:/testmount/newfile\": no such file or directory" newfile a+ -returnCodes error + testzipfswrite store-w teststored.zip "xyz" abac-repeat.txt w + testzipfswrite deflate-w testdeflated2.zip "xyz" abac-repeat.txt w + testzipfswrite store-wr teststored.zip "xyz" abac-repeat.txt w+ + testzipfswrite deflate-wr testdeflated2.zip "xyz" abac-repeat.txt w+ + testzipfswrite stored-a teststored.zip "append mode not supported: permission denied" abac-repeat.txt a -returnCodes error + testzipfswrite deflate-a testdeflated2.zip "append mode not supported: permission denied" abac-repeat.txt a -returnCodes error + testzipfswrite store-ar teststored.zip "aaaaaaaaaaaaaa\nbbbbbbbbbbbbbb\naaaaaaaaaaaaaa\ncccccccccccccc\nxyz" abac-repeat.txt a+ + testzipfswrite deflate-ar testdeflated2.zip "aaaaaaaaaaaaaa\nbbbbbbbbbbbbbb\naaaaaaaaaaaaaa\ncccccccccccccc\nxyz" abac-repeat.txt a+ + + test zipfs-write-unreadable "Reads not allowed on file opened for write" -setup { + mount [zippath test.zip] + } -cleanup { + close $fd + cleanup + } -body { + set fd [open [file join $defaultMountPoint test] w] + read $fd + } -result {channel "*" wasn't opened for reading} -match glob -returnCodes error + + test zipfs-write-persist "Writes persist ONLY while mounted" -setup { + mount [zippath test.zip] + } -cleanup { + cleanup + } -body { + set path [file join $defaultMountPoint test] + set fd [open $path w] + puts -nonewline $fd newtext + close $fd + set fd [open $path] + set result [list [read $fd]] + close $fd + zipfs unmount $defaultMountPoint + mount [zippath test.zip] + set fd [open $path] + lappend result [read $fd] + close $fd + set result + } -result [list newtext test\n] + + test zipfs-write-size-limit-0 "Writes have a size limit" -setup { + set origlimit $::tcl::zipfs::wrmax + mount [zippath test.zip] + } -cleanup { + close $fd + set ::tcl::zipfs::wrmax $origlimit + cleanup + } -body { + set ::tcl::zipfs::wrmax 10 + set fd [open [file join $defaultMountPoint test] w] + puts -nonewline $fd [string repeat x 11] + } -result {} -returnCodes error -constraints bug-d5d03207ca + + test zipfs-write-size-limit-1 "Writes disallowed" -setup { + set origlimit $::tcl::zipfs::wrmax + mount [zippath test.zip] + } -cleanup { + set ::tcl::zipfs::wrmax $origlimit + cleanup + } -body { + set ::tcl::zipfs::wrmax -1 + open [file join $defaultMountPoint test] w + } -result {write access not supported: permission denied} -returnCodes error + + # + # read/seek/write + proc testzipfsrw {id zippath expected filename mode args} { + variable defaultMountPoint + set zippath [zippath $zippath] + set path [file join $defaultMountPoint $filename] + set body { + set result "" + set fd [open $path $mode] + fconfigure $fd -translation binary + append result [gets $fd], + set pos [tell $fd] + append result $pos, + puts -nonewline $fd "xyz" + append result [gets $fd], + seek $fd $pos + append result [gets $fd], + seek $fd -6 end + append result [read $fd] + } + test zipfs-readwrite-$id "zipfs read/seek/write $id" -setup { + unset -nocomplain fd + zipfs mount $zippath $defaultMountPoint + } -cleanup { + # In case open succeeded when it should not + if {[info exists fd]} { + close $fd + } + cleanup + } -body $body -result $expected {*}$args + set data [readbin $zippath] + test zipfs-readwrite-memory-$id "zipfs read/seek/write in-memory $id" -setup { + unset -nocomplain fd + zipfs mount_data $data $defaultMountPoint + } -cleanup { + # In case open succeeded when it should not + if {[info exists fd]} { + close $fd + } + cleanup + } -body $body -result $expected {*}$args + + } + testzipfsrw store-r+ teststored.zip "aaaaaaaaaaaaaa,15,bbbbbbbbbbb,xyzbbbbbbbbbbb,ccccc\n" abac-repeat.txt r+ + testzipfsrw store-w+ teststored.zip ",0,,xyz,yz" abac-repeat.txt w+ -constraints bug-00018ec7a0 + testzipfsrw store-a+ teststored.zip ",60,,xyz,cc\nxyz" abac-repeat.txt a+ + + # + # Password protected proc testpassword {id filename password result args} { variable defaultMountPoint set zippath [zippath test-password.zip] @@ -977,7 +1160,7 @@ namespace eval test_ns_zipfs { zipfs mount $zippath $defaultMountPoint } } -cleanup { - # In case mount succeeded when it should not + # In case open succeeded when it should not if {[info exists fd]} { close $fd } @@ -987,15 +1170,15 @@ namespace eval test_ns_zipfs { gets $fd } -result $result {*}$args } - # The bug bbe7c6ff9e only manifests on macos - testConstraint bbe7c6ff9e [expr {$::tcl_platform(os) ne "Darwin"}] + # The bug bug-bbe7c6ff9e only manifests on macos + testConstraint bug-bbe7c6ff9e [expr {$::tcl_platform(os) ne "Darwin"}] testpassword plain plain.txt password plaintext testpassword plain-nopassword plain.txt "" plaintext testpassword plain-badpassword plain.txt xxx plaintext - testpassword cipher cipher.bin password ciphertext -constraints bbe7c6ff9e + testpassword cipher cipher.bin password ciphertext -constraints bug-bbe7c6ff9e testpassword cipher-nopassword cipher.bin {} "decryption failed" -returnCodes error testpassword cipher-badpassword cipher.bin xxx "invalid CRC" -returnCodes error - testpassword cipher-deflate cipher-deflate.bin password [lseq 100] -constraints bbe7c6ff9e + testpassword cipher-deflate cipher-deflate.bin password [lseq 100] -constraints bug-bbe7c6ff9e testpassword cipher-deflate-nopassword cipher-deflate.bin {} "decryption failed" -returnCodes error testpassword cipher-deflate-badpassword cipher-deflate.bin xxx "decompression error" -returnCodes error -- cgit v0.12