r-lib / zip

Platform independent zip compression via miniz
https://r-lib.github.io/zip/
Other
83 stars 19 forks source link

Filenames with colons cannot be added to archive #70

Closed enricoschumann closed 1 year ago

enricoschumann commented 3 years ago

When I try to create an archive from files that have colons in their names, I get an error:

filedir <- tempdir()
## browseURL(filedir)

filename <- "aaa:bbb.txt"
writeLines("test", file.path(filedir, filename))

zip::zip(file.path(filedir, "colon.zip"),
         files = filename,
         root = filedir)
Error in zip_internal(zipfile, files, recurse, compression_level, append = FALSE,  : 
  zip error: `Cannot add file `aaa:bbb.txt` to archive `/tmp/RtmpxBaRKe/colon.zip`` in file `zip.c:348`

This happens on R 4.0.3 on Ubuntu 20.10. I am aware that colons are not allowed on Windows, but is this a general/documented limitation of zip?

gaborcsardi commented 3 years ago

I don't think it is a zip format limitation, but it could be a minizip limitation.

jbfagotfede39 commented 2 years ago

Same problem on :

Zip tool included in OSX replace : by / alone.

gaborcsardi commented 1 year ago

Indeed a miniz limitation:

static mz_bool mz_zip_writer_validate_archive_name(const char *pArchive_name)
{
    /* Basic ZIP archive filename validity checks: Valid filenames cannot start with a forward slash, cannot contain a drive letter, and cannot use DOS-style backward slashes. */
    if (*pArchive_name == '/')
        return MZ_FALSE;

    while (*pArchive_name)
    {
        if ((*pArchive_name == '\\') || (*pArchive_name == ':'))
            return MZ_FALSE;

        pArchive_name++;
    }

    return MZ_TRUE;
}
gaborcsardi commented 1 year ago

We could work around this, macOS builtin zip happily creates a zip file with : in the file name. OTOH I suspect that this is going to cause issues on Windows.

gaborcsardi commented 1 year ago

Closed by https://github.com/r-lib/zip/commit/2c56de4aaae24da27192c3f2d04cc347e32b1b98.