Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Asar #378

Merged
merged 14 commits into from
Aug 1, 2020
Merged

Conversation

dyoshikawa
Copy link
Contributor

@dyoshikawa dyoshikawa commented Jul 14, 2020

Fixes #375

The official page of the file format

https://github.com/electron/asar#format

@dyoshikawa dyoshikawa mentioned this pull request Jul 14, 2020
@Richienb
Copy link
Contributor

// @sindresorhus

@Richienb
Copy link
Contributor

@dyoshikawa In the pull request message, change For to Fixes so that the issue can be automatically closed.

@dyoshikawa
Copy link
Contributor Author

@Richienb Thanks. Changed my message.

Co-authored-by: Richie Bendall <[email protected]>
@Richienb
Copy link
Contributor

As it turns out, asar doesn't actually have a mime type so it should be set to application/octet-stream. electron/asar#199 (comment)

@dyoshikawa
Copy link
Contributor Author

As it turns out, asar doesn't actually have a mime type so it should be set to application/octet-stream. electron/asar#199 (comment)

Can we use original mime type name?
ex. application/x-asar

@Richienb
Copy link
Contributor

@dyoshikawa Not sure. Try asking that on electron/asar#199

@dyoshikawa
Copy link
Contributor Author

@Richienb

https://www.iana.org/assignments/media-types/media-types.xhtml

Unregisterd mime types in this library seems to already exist.
ex. application/x-sqlite3, application/x-google-chrome-extension and more.

https://tools.ietf.org/html/rfc6838#section-3.4

Subtype names with "x." as the first facet may be used for types intended exclusively for use in private, local environments.

So application/x.asar looks good to me.

@Richienb
Copy link
Contributor

🤷‍♂️

@bencmbrook
Copy link
Contributor

bencmbrook commented Jul 21, 2020

Unregisterd mime types in this library seems to already exist.

These unregistered types are still used elsewhere so there's at least some traction behind them.

So application/x.asar looks good to me.

Since x. is "intended exclusively for use in private, local environments", it doesn't work here.

I don't think this library should create new MIME types. It should be the responsibility of the community around the format to decide on and register their MIME type. Given application/x-asar is not used elsewhere, I'd like to see this MIME as application/octet-stream.

@Borewit
Copy link
Collaborator

Borewit commented Jul 22, 2020

Consistent with existing code, I think we can use application/x-asar. /x- indicates an unregistered MIME-type.
We use an extensions and MIME-types to express the identified file type.
Both of them are not perfect. Wherever possible we shall comply with the standard.

@dyoshikawa
Copy link
Contributor Author

@Borewit Thanks.
I rewrote checking logic by 2 steps.
And, I adopted application/x-asar as mime type.

dyoshikawa and others added 2 commits July 27, 2020 14:40
Co-authored-by: Richie Bendall <[email protected]>
Co-authored-by: Richie Bendall <[email protected]>
core.js Outdated
if (buffer.length > 16 && checkString('{"files":{', {offset: 16})) {
try {
// Check header_size
buffer.readUInt32LE(4);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unlike the comment suggests, there is in fact nothing checked here.
The header size is read, but the result is ignored.

Should the result not be used:

  • to check the format
  • determine the length of the JSON payload?

If required, note that buffer.readUInt32LE(4) can be executed safely on any file, as long as there are 4 bytes available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.
I think this line should delete because your opinion.
Do you think so, too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Go ahead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sir.

core.js Outdated
@@ -1355,6 +1355,24 @@ async function _fromTokenizer(tokenizer) {
}
}
}

// Check for Asar
if (buffer.length > 16 && checkString('{"files":{', {offset: 16})) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The checkString will only succeed if the string exist at that location, so no need to check the buffer length yourself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thx. I adopted it.

dyoshikawa and others added 3 commits July 28, 2020 22:01
Co-authored-by: Richie Bendall <[email protected]>
Move the test in the "256-byte" group.
Gradually check if format is ASAR/Pickle.
@@ -1367,7 +1385,8 @@ const stream = readableStream => new Promise((resolve, reject) => {
const pass = new stream.PassThrough();
let outputStream;
if (stream.pipeline) {
outputStream = stream.pipeline(readableStream, pass, () => {});
outputStream = stream.pipeline(readableStream, pass, () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Borewit
Is it needed?
This diff looks only a new line.

Copy link
Contributor

Choose a reason for hiding this comment

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

Best remove this newline.

Copy link
Contributor Author

@dyoshikawa dyoshikawa left a comment

Choose a reason for hiding this comment

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

@Borewit Thank you.
I adopted your suggesting code.

@@ -1195,6 +1195,24 @@ async function _fromTokenizer(tokenizer) {
};
}

if (check([0x04, 0x00, 0x00, 0x00]) && buffer.length >= 16) { // Rough & quick check Pickle/ASAR
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all of these comments necessary?

@Richienb
Copy link
Contributor

Richienb commented Aug 1, 2020

@sindresorhus

@Borewit Borewit merged commit f2ebb8d into sindresorhus:master Aug 1, 2020
@dyoshikawa
Copy link
Contributor Author

Thank you for everyone!

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.

Add asar support
5 participants