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 issue 20027 - std.zip susceptible to zip malware attacks #7223

Merged
merged 1 commit into from Oct 10, 2019
Merged

Fix issue 20027 - std.zip susceptible to zip malware attacks #7223

merged 1 commit into from Oct 10, 2019

Conversation

ghost
Copy link

@ghost ghost commented Oct 10, 2019

This fixes the main problem of 20027, namely rejecting zip bombs. I moved all remaining problems to own issues (20290 - 20294). Therefore this issue can be closed with this PR.

There is one unittest missing, namely checking for overlaps of zip64 central dir records with other stuff. This unittests needs to be postponed due to a bug in the implementation of zip64 (see issue 20289).

I verified, that it indeed rejects the zip bombs zbsm.zip and zblg.zip mentioned in the issues. The zip64 zip bomb zbxl.zip does not work yet due to bugs in the zip64 implementation, probably introduced by me in PR #7198. I'll fix this as soon as possible.

I also checked some normal zip-files to make sure that the size of _segs is always O(1).

@ghost ghost requested a review from CyberShadow as a code owner October 10, 2019 19:10
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @berni44! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
20027 major std.zip susceptible to zip malware attacks

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + phobos#7223"

int endcommentlength = getUshort(i + 20);
comment = cast(string)(_data[i + 22 .. i + 22 + endcommentlength]);
int endCommentLength = getUshort(i + 20);
comment = cast(string)(_data[i + 22 .. i + 22 + endCommentLength]);
Copy link
Member

Choose a reason for hiding this comment

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

It would have been good to put style fixes in their own commit.

@@ -726,6 +741,10 @@ public:
auto localFileHeaderNamelen = getUshort(de.offset + 26);
auto localFileHeaderExtralen = getUshort(de.offset + 28);

// file data
removeSegment(de.offset, de.offset + localFileHeaderLength + localFileHeaderNamelen
+ localFileHeaderExtralen + de._compressedSize);
Copy link
Member

Choose a reason for hiding this comment

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

I'm hoping all of these can be later refactored away to avoid the DRY of calculating all these lengths all over the place. The code is pretty difficult to follow as it is. Maybe once the structures are represented as D structs, the removeSegment call can be done by whatever function will be doing the reading of the entire structs.

Copy link
Member

Choose a reason for hiding this comment

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

Here is my code to read a Windows PE file's headers:

https://github.com/CyberShadow/ae/blob/218c29e17f6ecfc49f696b92c879c5c6b9917f2e/sys/windows/pe/pe.d#L31-L51

I'm hoping std.zip could closer to that.

@dlang-bot dlang-bot merged commit f416493 into dlang:master Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants