gildas-lormeau / zip.js

JavaScript library to zip and unzip files supporting multi-core compression, compression streams, zip64, split files and encryption.
https://gildas-lormeau.github.io/zip.js
BSD 3-Clause "New" or "Revised" License
3.38k stars 510 forks source link

File permissions #405

Closed michalzaq12 closed 1 year ago

michalzaq12 commented 1 year ago

Does this library support storing permissions? Something similar to: https://stuk.github.io/jszip/documentation/api_jszip/file_data.html#unixpermissions-and-dospermissions-options.

Unfortunately, this is a big problem when there are e.g. OSX applications in the zip, you need to grant them execute permissions.

gildas-lormeau commented 1 year ago

It's possible via the the versionMadeBy and the externalFileAttribute options, see resp. 4.4.2 and 4.4.15 here https://pkware.cachefly.net/webdocs/APPNOTE/APPNOTE-6.3.9.TXT. I don't yet where to find a reliable source to get more details on how to set the externalFileAttribute value properly.

michalzaq12 commented 1 year ago

Thanks for your reply, the attributes don't seem to be set correctly.

My code in NodeJS

const data = fs.createReadStream('./in.zip');
const zipFs = new zipFsNamespace.FS();
await zipFs.importReadable(Readable.toWeb(data));

const exeEntry = zipFs.find('executable');
console.log('file attr:', exeEntry.data.externalFileAttribute) // file attr: 2179792896

const outStream = fs.createWriteStream('./out.zip');
zipFs.exportWritable(Writable.toWeb(outStream));

Once exported, the "executable" file can no longer be run. Moreover, if I import the file 'out.zip' and read externalFileAttribute again, it is zero.

michalzaq12 commented 1 year ago

This issue also occurs on: https://gildas-lormeau.github.io/zipjs-react-app/

  1. Import zip (eg. https://github.com/jakob/TableTool/releases/download/v1.2.1/tabletool-1.2.1.zip)
  2. Export zip
  3. Try to open exported app on OSX
  4. Error: The application “Table Tool 2” can’t be opened. (due to lack of proper permissions)
gildas-lormeau commented 1 year ago

The FS API is still a bit limited and does not provide a way to copy these metadata yet. However, you should be able to read and write the versionMadeBy and the externalFileAttributeproperties/options when using the ZipReader/ZipWriter APIs.

gildas-lormeau commented 1 year ago

I did not say I would not implement this feature request.

gildas-lormeau commented 1 year ago

This should be fixed in the version 2.6.81 I just published.