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

Prevent potential size overflow and 0 length PATCH #556

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,12 @@ class BaseUpload {
end = this._size
}

const sliceSize = end - start
if (sliceSize <= 0) { // done
req.setHeader('Upload-Length', this._size)
return this._sendRequest(req)
}

return this._source.slice(start, end)
.then(({ value, done }) => {
// If the upload length is deferred, the upload size was not specified during
Expand Down Expand Up @@ -775,7 +781,7 @@ class BaseUpload {

this._offset = offset

if (offset === this._size) {
if (offset >= this._size) {
// Yay, finally done :)
this._emitSuccess()
this._source.close()
Expand Down