diff options
author | apnadkarni <apnmbx-wits@yahoo.com> | 2023-09-26 05:22:22 (GMT) |
---|---|---|
committer | apnadkarni <apnmbx-wits@yahoo.com> | 2023-09-26 05:22:22 (GMT) |
commit | b730c0e5a483d8a0a348f211aadf08ec8e19be70 (patch) | |
tree | 46ffefd087b758ee809494281abb77f9bbb8db1f | |
parent | d3ec5a1fb59c1b5e51d4492e69d5205300e3f2e8 (diff) | |
parent | b19cf92301ef772bd85dafa484d8271bd046f917 (diff) | |
download | tcl-b730c0e5a483d8a0a348f211aadf08ec8e19be70.zip tcl-b730c0e5a483d8a0a348f211aadf08ec8e19be70.tar.gz tcl-b730c0e5a483d8a0a348f211aadf08ec8e19be70.tar.bz2 |
Bug [d5d03207ca] - Tcl hang on zipfs writes greater than buffer size
-rw-r--r-- | generic/tclZipfs.c | 15 | ||||
-rw-r--r-- | tests/zipfs.test | 33 |
2 files changed, 36 insertions, 12 deletions
diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index 510fa33..69c1421 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -4338,18 +4338,17 @@ ZipChannelWrite( ZipChannel *info = (ZipChannel *) instanceData; unsigned long nextpos; - if (!info->isWriting) { + if (toWrite == 0 || !info->isWriting) { *errloc = EINVAL; return -1; } - nextpos = info->numRead + toWrite; - if (nextpos > info->maxWrite) { - toWrite = info->maxWrite - info->numRead; - nextpos = info->maxWrite; - } - if (toWrite == 0) { - return 0; + assert(info->maxWrite >= info->numRead); + if (toWrite > (int) (info->maxWrite - info->numRead)) { + /* Don't do partial writes in error case. Or should we? */ + *errloc = EFBIG; + return -1; } + nextpos = info->numRead + toWrite; memcpy(info->ubuf + info->numRead, buf, toWrite); info->numRead = nextpos; if (info->numRead > info->numBytes) { diff --git a/tests/zipfs.test b/tests/zipfs.test index 2c4775f..cb45b05 100644 --- a/tests/zipfs.test +++ b/tests/zipfs.test @@ -1073,7 +1073,7 @@ namespace eval test_ns_zipfs { set result } -result [list newtext test\n] - test zipfs-write-size-limit-0 "Writes have a size limit" -setup { + test zipfs-write-size-limit-0 "Writes more than size limit with flush" -setup { set origlimit $::tcl::zipfs::wrmax mount [zippath test.zip] } -cleanup { @@ -1083,10 +1083,35 @@ namespace eval test_ns_zipfs { } -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 + puts $fd [string repeat x 11] + flush $fd + } -result {error flushing *: file too large} -match glob -returnCodes error - test zipfs-write-size-limit-1 "Writes disallowed" -setup { + test zipfs-write-size-limit-1 "Writes size limit on close" -setup { + set origlimit $::tcl::zipfs::wrmax + mount [zippath test.zip] + } -cleanup { + set ::tcl::zipfs::wrmax $origlimit + cleanup + } -body { + set ::tcl::zipfs::wrmax 10 + set fd [open [file join $defaultMountPoint test] w] + puts $fd [string repeat x 11] + close $fd + } -result {file too large} -match glob -returnCodes error + + test zipfs-write-size-limit-2 "Writes max size" -setup { + mount [zippath test.zip] + } -cleanup { + cleanup + } -body { + set fd [open [file join $defaultMountPoint test] w] + puts -nonewline $fd [string repeat x $::tcl::zipfs::wrmax] + close $fd + file size [file join $defaultMountPoint test] + } -result $::tcl::zipfs::wrmax + + test zipfs-write-size-limit-3 "Writes disallowed" -setup { set origlimit $::tcl::zipfs::wrmax mount [zippath test.zip] } -cleanup { |