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

Fix mimetype umask #18

Merged
merged 1 commit into from
Feb 26, 2018
Merged

Conversation

clee
Copy link
Contributor

@clee clee commented Feb 25, 2018

I found an ebook reader that didn't like the total lack of file permissions set for the embedded 'mimetype' file generated during the epub packaging process. This one-line change sets the permissions in the zip file to be the same as rw-r--r-- on a normal UNIX system.

@kevinhendricks
Copy link
Owner

kevinhendricks commented Feb 25, 2018 via email

@clee
Copy link
Contributor Author

clee commented Feb 25, 2018

I had never seen it either! The reader is called Bookworm. https://github.com/babluboy/bookworm

It complains about invalid mime types when you try to open ePub files generated by KindleUnpack pre-patch.

I’m running it on Fedora 27.

Although it's worth noting that if I use the standard 'unzip' utility on a KindleUnpack-generated epub, the mimetype file's permissions ARE set to 000 when expanded to the local filesystem. My umask does not appear to be used at all.

@kevinhendricks
Copy link
Owner

kevinhendricks commented Feb 25, 2018 via email

@kevinhendricks
Copy link
Owner

kevinhendricks commented Feb 25, 2018 via email

@kevinhendricks
Copy link
Owner

kevinhendricks commented Feb 25, 2018 via email

@clee
Copy link
Contributor Author

clee commented Feb 25, 2018

I'm using Python 2.7.14. My user's umask is '002'. Very strange!

I wasn't trying to read my KF8 books in Bookworm; I had some that I had manually converted to epubs using KindleUnpack, and I was trying to load those epubs. All of these epubs were generated using Python 2.7.14, on the latest master of KindleUnpack (before this commit). Every one of them has a mimetype with 0o000 permissions. :/

@clee
Copy link
Contributor Author

clee commented Feb 25, 2018

@kevinhendricks Can you verify for me that if you unzip an epub generated in the mobi8 subdir from python lib/kindleunpack.py -s <KF8file>, the 'mimetype' file is not 0o000? I'm very curious to figure out where this is getting broken.

@clee
Copy link
Contributor Author

clee commented Feb 25, 2018

Ah! I figured it out.

If you look in the zipfile source (around line 1221 for me locally at /usr/lib/python2.7/zipfile.py), you can see that the code that automatically sets the external_attr to 0o600 is nested in a check for if not isinstance(zinfo_or_arcname, ZipInfo); the KindleUnpack code is passing in a ZipInfo object already when calling writestr, which means we don't get the benefit of the automatic external_attr setting, so we have to set it ourselves.

@dougmassay
Copy link
Collaborator

dougmassay commented Feb 25, 2018

Unzipping the epub unpacked from a KF8 with your above command (minus the split option which wasn't relevant) gives me a mimetype file with 0o600 permissions.

@clee
Copy link
Contributor Author

clee commented Feb 25, 2018

@dougmassay Which Python version? When I use KindleUnpack with python 3.6.3, the 'mimetype' looks like it comes out with the correct permissions; when I use KindleUnpack with python 2.7.14, it's 0o000.

@dougmassay
Copy link
Collaborator

I used my default Python 3.6.4.

You're right. With Python 2.7.14, I'm getting a mimetype file with no permissions at all.

@clee
Copy link
Contributor Author

clee commented Feb 25, 2018

Glad to know I'm not completely crazy :)

@kevinhendricks
Copy link
Owner

kevinhendricks commented Feb 25, 2018 via email

I found an ebook reader that didn't like the total lack of file
permissions set for the embedded 'mimetype' file generated during the
epub packaging process. This one-line change sets the permissions in the
zip file to be the same as rw------- on a normal UNIX system.
@clee
Copy link
Contributor Author

clee commented Feb 25, 2018

PR updated with a new version that sets the default to 0o600 as requested. Tested with Bookworm locally and it still fixes the problem. Thanks for the quick response!

@kevinhendricks kevinhendricks merged commit 595eba7 into kevinhendricks:master Feb 26, 2018
@kevinhendricks
Copy link
Owner

Thanks for your PR

@dougmassay
Copy link
Collaborator

@clee: the commits in this pull request were not tested with Python 3; and in fact prevented the program from launching at all with Python 3 (as reported in issue #21). I adjusted (bbb6967) so that it should be compatible with Python 2.7.x+ and Python 3.x+. Not sure about Pythons earlier than 2.7.

Please make sure to test your Pull Requests with both Python 2 and Python 3. Thanks.

@dougmassay dougmassay mentioned this pull request Mar 3, 2018
@clee
Copy link
Contributor Author

clee commented Mar 3, 2018

@dougmassay Damn, I thought I had tested it with 3.6! Obviously not. Sorry!

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.

3 participants