-
Notifications
You must be signed in to change notification settings - Fork 112
fix deflation of epub files with abnormal zip header #315
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
base: master
Are you sure you want to change the base?
Conversation
if unpSize is detected correctly but packSize is not, use packSize provided by central director instead
Please check InfoZip AppNote 6.3.9:
Can you check this flag with this files? coolreader/crengine/src/lvstream/ziphdr.h Line 24 in 682fb3e
Perhaps you need to add yet another workaround for this case. |
Also, please format the code to match the formatting of this file (lvzipdecodestream.cpp). Thanks for the fix. Will there be no problems with catalogs/directories with these conditions? |
Regarding the formatting - will fix that as you prefer - I just kept the block for cosmetic reasons, i.e. to indicate where the comment is related to... Regressions - not sure how to deal with it - if you have a test suite somewhere or can give some files that you suspect to be problematic I can check them. |
The value of hdr.Flags is 8 for META-INF/content.xml => only bit 4 is set. The full contents of the hdr struct is:
...and this is the related zipinfo output:
Not sure if this helps... |
Unfortunately, we do not have any test suite, so you can just check the functionality on other zip files. Although your code looks safe, I think it shouldn't be a problem. |
You can also uncomment this line: coolreader/crengine/src/lvstream/lvziparc.cpp Line 364 in 682fb3e
and see in console some debug messages including contents of the extra fields. Description of this extra field you can find in InfoZip AppNote. |
Looks quite innofensive to me. |
There you go:
For your convenience I also tried an empty epub file (aka empty zip file) => no crashes / errors, I guess because it will never try to read META-INF/container.xml in this cause ;-) The first thing it tries to extract from epub zip is mimedata in zip root - which is not present in this case here, so the code will exit early. |
That was with an empty |
Isn't this information present in localzipheader and extra fields? |
No, that was with the original epub file. With empty container.xml the result is
=> notice that the original epub file does not have extra header data - opposed to the modified file I just created with empty container.xml |
OK, I don't want to put my head in the specs, so trusting you that your small fix is sane with various combinations of packSize / unpSize when only one is zero, and that it is sane to use only one of srcPackSize / srcUnpSize :) |
This fixes zip deflation bug triggered by some watermarked, DRM-free epub file which I bought from a book store. It seems to have been created with Adobe Indesign 9.2.
Cool Reader standalone (as well as KOReader on my Tolino based on crengine, see related issue koreader/koreader#8222) was unable to display it while other readers like the one from Calibre does not have issues. As soon as I extract all contents and re-compress them into a new epub file, Cool Reader did not have issues anymore, so the culprit lies in the binary zip structure of the epub file.
It turned out that packSize was detected as zero within LVZipDecodeStream::Create while unpSize was detected correctly, so the existing workaround did not kick in => I have separated it into two distinct if clauses.
Unfortunately I can't give you the epub due to the watermarking and copyright :-/