-
Notifications
You must be signed in to change notification settings - Fork 55
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
directory recv: add sanity checks before writing into the destination #86
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -199,6 +199,21 @@ func recvAction(cmd *cobra.Command, args []string) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
bail("Read zip error: %s", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// calculate the uncompressed size of the contents of the zip | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
var actualUncompressedSize uint64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
var fileCount int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for _, f := range zr.File { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
actualUncompressedSize += f.FileHeader.UncompressedSize64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fileCount++ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if msg.UncompressedBytes64 < int64(actualUncompressedSize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bail("error: uncompressed size of the directory mismatch with that in the offer message") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if msg.FileCount < fileCount { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bail("error: number of files in the directory mismatch with that in the offer message") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+202
to
+216
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realised that running
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the suggestion as I realised it actually makes more sense to check file counts before checking uncompressed size in this case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vu3rdd Any chance to get this improved so the PR perhaps can be merged after that? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for _, zf := range zr.File { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
p, err := filepath.Abs(filepath.Join(dirName, zf.Name)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a malicious zipfile I don't think we can trust the value of
UncompressedSize64