Skip to content

Improve ZIP compatibility#27

Merged
ctalkington merged 2 commits into
archiverjs:masterfrom
garymathews:compat
Oct 7, 2017
Merged

Improve ZIP compatibility#27
ctalkington merged 2 commits into
archiverjs:masterfrom
garymathews:compat

Conversation

@garymathews

@garymathews garymathews commented Aug 5, 2017

Copy link
Copy Markdown
Contributor
  • Some ZIP readers require the data descriptor bit to not be set when METHOD_STORED is used (e.g: java.util.zip.ZipInputStream)
  • Set mask on writeUInt32LE and writeUInt16LE to prevent out of bounds exception
  • Set default size and compressed size to zero for improved compatibility
NOTE: this should fix compatibility for Java Archives

@garymathews

Copy link
Copy Markdown
Contributor Author

@ctalkington had chance to take a look?

ZipArchiveOutputStream.prototype._appendStream = function(ae, source, callback) {
ae.getGeneralPurposeBit().useDataDescriptor(true);
ae.setVersionNeededToExtract(constants.MIN_VERSION_DATA_DESCRIPTOR);
if (ae.getMethod() === constants.METHOD_DEFLATED) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like this is going to cause issues. because with streaming we dont have the size yet. so the code in _writeLocalFileHeader (https://github.com/archiverjs/node-compress-commons/blob/master/lib/archivers/zip/zip-archive-output-stream.js#L405) is going to write zeros for size. since normally when a data descriptor is used the size is fixed at the end.

to keep the streaming interface and use this logic, we would have to buffer all the content leading to higher memory usage.

@garymathews garymathews Oct 7, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following similar logic here. But I've since updated the PR. Although, I'm not sure I follow? This seems to work fine?

this.name = null;
this.size = -1;
this.csize = -1;
this.size = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think was left over from older code and i thought it got set to 0 from one of the consumer modules but this will ensure such is a sane default. thanks.

Comment thread lib/archivers/zip/util.js
util.getShortBytes = function(v) {
var buf = new Buffer(2);
buf.writeUInt16LE(v, 0);
buf.writeUInt16LE((v & 0xFFFF) >>> 0, 0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a good idea. thanks.

@garymathews

Copy link
Copy Markdown
Contributor Author

@ctalkington Updated PR

@ctalkington ctalkington merged commit 0a2c38b into archiverjs:master Oct 7, 2017
@ctalkington

Copy link
Copy Markdown
Member

thanks for following up. working on getting a batch of bugfixes out this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants