From b4ec5b8f1d728d73d0e5449360a3352f5887b707 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Sat, 21 Dec 2019 08:28:34 -0500 Subject: [PATCH] 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. --- lib/gridfs-stream/upload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gridfs-stream/upload.js b/lib/gridfs-stream/upload.js index 40e1eab3ff..578949a53d 100644 --- a/lib/gridfs-stream/upload.js +++ b/lib/gridfs-stream/upload.js @@ -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;