From 3dce0b31fc75ae153d7e698c1adde5de6fd7dec3 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Mon, 25 Sep 2023 19:45:15 +0000 Subject: Start on [d5d03207ca] --- generic/tclZipfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index 510fa33..ceccd9e 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -4342,14 +4342,14 @@ ZipChannelWrite( *errloc = EINVAL; return -1; } - nextpos = info->numRead + toWrite; - if (nextpos > info->maxWrite) { + if (toWrite > info->maxWrite - info->numRead) { toWrite = info->maxWrite - info->numRead; - nextpos = info->maxWrite; } if (toWrite == 0) { - return 0; + *errloc = EFBIG; + return -1; } + nextpos = info->numRead + toWrite; memcpy(info->ubuf + info->numRead, buf, toWrite); info->numRead = nextpos; if (info->numRead > info->numBytes) { -- cgit v0.12 From b19cf92301ef772bd85dafa484d8271bd046f917 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Tue, 26 Sep 2023 05:03:28 +0000 Subject: Add tests --- generic/tclZipfs.c | 4 +--- tests/zipfs.test | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index ceccd9e..63392b8 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -4343,9 +4343,7 @@ ZipChannelWrite( return -1; } if (toWrite > info->maxWrite - info->numRead) { - toWrite = info->maxWrite - info->numRead; - } - if (toWrite == 0) { + /* Don't do partial writes in error case. Or should we? */ *errloc = EFBIG; return -1; } 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 { -- cgit v0.12