Skip to content

Commit b4ec5b8

Browse files
committed
fix(gridfs): make a copy of chunk before writing to server
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.
1 parent b24e33e commit b4ec5b8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/gridfs-stream/upload.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ function doWrite(_this, chunk, encoding, callback) {
422422
if (_this.md5) {
423423
_this.md5.update(_this.bufToStore);
424424
}
425-
var doc = createChunkDoc(_this.id, _this.n, _this.bufToStore);
425+
var doc = createChunkDoc(_this.id, _this.n, Buffer.from(_this.bufToStore));
426426
++_this.state.outstandingRequests;
427427
++outstandingRequests;
428428

0 commit comments

Comments
 (0)