fix(streamingUnzip): avoid detection of incorrect ZIP signature - #275
cyfung1031 wants to merge 1 commit into
Conversation
|
because #235 is due to the streaming Unzip mixed up the ZIP signatures of the stored zip files and the one it is working on. |
because #208 is due to the wrong detection of EOL due to the ZIP signature detection |
|
please @101arrowz, give some attention to this PR. I was about to open a new open addressing the same issue. This is really hard to reproduce and pinpoint the issue is even harder. |
|
tbf @cyfung1031 it would be nice if we added tests that validated this scenario. @101arrowz let me know if this is the blocker for the acceptance of the PR I can grab it and open a new one with proper tests |
if you see the repo, there are almost no test. https://github.com/101arrowz/fflate/blob/master/test/3-zip.ts anyway, finally I figure out that streaming zip is not practicable for web application. I made my own reliable library JSZipp which is full of testing. just no streaming zip/unzip. |
(Although the code is generated by AI but since 101arrowz do not like AI paragraphs so I write the following)
This is to solve the current design limit of streaming Unzip - causing issue #243.
When it scan the ZIP signatures like 0x8074B50, 0x4034B50, 0x2014B50, etc, it will believe this is end of file.
but this is incorrect since the compressed file might also contain such bytes by chance.
now the field "b" is added to represent "compressed bytes flushed so far for the current data-descriptor entry"
Then using
this.b + candidateEndOffsetto check whether the compression data matches descriptor, rather than just trusting the ZIP signature bytes.( A real boundary is always preceded by a data descriptor whose csize field must equal the bytes consumed so far. )
btw
z = oc == -2 && 8is for zip64 data descriptors detection. So that it can check with the 64-bit size as well.if you still don't like AI coding, just take it as a reference and do it yourself.
The coding isn't changed too much and you can read.
In addition