From 1e8ecbdd537a4d9c8295c215277a3f381efae74c Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Mon, 18 Sep 2023 15:47:06 +0000 Subject: Directory depth calculation assumed zipfs root at /, not //zipfs:/ --- generic/tclZipfs.c | 10 +++++++--- tests/zipfs.test | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index a38bc5b..42d9899 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -84,6 +84,7 @@ static const z_crc_t* crc32tab; */ #define ZIPFS_VOLUME "//zipfs:/" +#define ZIPFS_ROOTDIR_DEPTH 3 /* Number of / in root mount */ #define ZIPFS_VOLUME_LEN 9 #define ZIPFS_APP_MOUNT ZIPFS_VOLUME "app" #define ZIPFS_ZIP_MOUNT ZIPFS_VOLUME "lib/tcl" @@ -1728,6 +1729,7 @@ ZipFSCatalogFilesystem( Tcl_SetHashValue(hPtr, z); z->depth = CountSlashes(mountPoint); + assert(z->depth >= ZIPFS_ROOTDIR_DEPTH); z->zipFilePtr = zf; z->isDirectory = (zf->baseOffset == 0) ? 1 : -1; /* root marker */ z->offset = zf->baseOffset; @@ -1816,6 +1818,7 @@ ZipFSCatalogFilesystem( fullpath = CanonicalPath(mountPoint, path, &fpBuf, 1); z = AllocateZipEntry(); z->depth = CountSlashes(fullpath); + assert(z->depth >= ZIPFS_ROOTDIR_DEPTH); z->zipFilePtr = zf; z->isDirectory = isdir; z->isEncrypted = @@ -1853,7 +1856,7 @@ ZipFSCatalogFilesystem( z->name = (char *) Tcl_GetHashKey(&ZipFS.fileHash, hPtr); z->next = zf->entries; zf->entries = z; - if (isdir && (mountPoint[0] == '\0') && (z->depth == 1)) { + if (isdir && (mountPoint[0] == '\0') && (z->depth == ZIPFS_ROOTDIR_DEPTH)) { z->tnext = zf->topEnts; zf->topEnts = z; } @@ -1863,7 +1866,7 @@ ZipFSCatalogFilesystem( * containing directory nodes. */ - if (!z->isDirectory && (z->depth > 1)) { + if (!z->isDirectory && (z->depth > ZIPFS_ROOTDIR_DEPTH)) { char *dir, *endPtr; ZipEntry *zd; @@ -1884,6 +1887,7 @@ ZipFSCatalogFilesystem( zd = AllocateZipEntry(); zd->depth = CountSlashes(dir); + assert(zd->depth > ZIPFS_ROOTDIR_DEPTH); zd->zipFilePtr = zf; zd->isDirectory = 1; zd->offset = z->offset; @@ -1893,7 +1897,7 @@ ZipFSCatalogFilesystem( zd->name = (char *) Tcl_GetHashKey(&ZipFS.fileHash, hPtr); zd->next = zf->entries; zf->entries = zd; - if ((mountPoint[0] == '\0') && (zd->depth == 1)) { + if ((mountPoint[0] == '\0') && (zd->depth == ZIPFS_ROOTDIR_DEPTH)) { zd->tnext = zf->topEnts; zf->topEnts = zd; } diff --git a/tests/zipfs.test b/tests/zipfs.test index 6c3caee..88b2814 100644 --- a/tests/zipfs.test +++ b/tests/zipfs.test @@ -710,7 +710,7 @@ namespace eval test_ns_zipfs { # Some tests have !zipfslib constraint because otherwise they dump the entire Tcl library which is mounted on root testzipfslist no-mounts "" {} {} -constraints !zipfslib testzipfslist no-pattern "" {test.zip testmountA} {testmountA testmountA/test testmountA/testdir testmountA/testdir/test2} -constraints !zipfslib - testzipfslist no-pattern-mount-on-root "" {test.zip {}} {{} test testdir testdir/test2} -constraints bug-d056ee6d30 + testzipfslist no-pattern-mount-on-root "" {test.zip {}} {{} test testdir testdir/test2} 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 -- cgit v0.12