Skip to content

Commit

Permalink
fix(gridfs): make a copy of chunk before writing to server
Browse files Browse the repository at this point in the history
A shared buffer is used for gridfs uploads, but there is a race
where the buffer could be changed before the write has a chance to
execute. Instead, we cut a copy of the buffer for use during the
write operation.
  • Loading branch information
mbroadst committed Dec 30, 2019
1 parent b24e33e commit b4ec5b8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/gridfs-stream/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ function doWrite(_this, chunk, encoding, callback) {
if (_this.md5) {
_this.md5.update(_this.bufToStore);
}
var doc = createChunkDoc(_this.id, _this.n, _this.bufToStore);
var doc = createChunkDoc(_this.id, _this.n, Buffer.from(_this.bufToStore));
++_this.state.outstandingRequests;
++outstandingRequests;

Expand Down

0 comments on commit b4ec5b8

Please sign in to comment.