decompress-unzip icon indicating copy to clipboard operation
decompress-unzip copied to clipboard

Directory mistaken for file

Open kenlyon opened this issue 8 years ago • 2 comments

I've encountered an error unzipping an archive that appears to be a special case. I'm actually using gulp-decompress but the cause appears to be in this module.

Symptoms:

  1. One of the directories within the zip file is incorrectly identified as a file instead of a directory.
  2. An empty file is created instead of a directory.
  3. The unzip operation fails when it then attempts to unzip the files within that directory as the OS attempts to create a directory of the same name as the file.

Possible cause:

  1. The entry in question has a externalFileAttributes value of 0x00110000. This fails the equality comparison with16 because 0x00100000 is set.

I don't know enough about what the 0x00100000 bit is for to know if getType(entry, mode) should really be just checking for 0x00010000 being set, rather than an exact equality.

I tested using new zip archives that I created with 7zip and Windows right-click > Send to > Compressed (zipped) folder. Both of them worked correctly.

I am unable to share the zip file here as it's an installer for licensed software. I also have no idea how it was produced. However, I am happy to answer any questions or run additional tests as needed.

kenlyon avatar Apr 26 '17 16:04 kenlyon

Any update on this? It took a bit of effort to provide this level of detail. It'd be nice to get some feedback.

kenlyon avatar May 10 '17 23:05 kenlyon

This might help in some situations (as long as you're sure there aren't any real filenames ending with /):

  decompress(buffer, dir, {
    map: (file) => {
      if (file.type === 'file' && file.path.endsWith('/')) {
        file.type = 'directory'
      }
      return file
    },
  })

hubgit avatar Oct 27 '20 20:10 hubgit