From 8a47640f88e441ceaeb9be3144267e497a3b4f43 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Tue, 19 Jun 2018 17:12:51 -0700 Subject: [PATCH 1/3] Fix for empty data in block. Found this very strange bug when creating DAGNode's with empty buffers for data. streamToValue returns an empty array when the data is empty, which down the line triggers an exception in ipfs-block because this sends an empty array instead of a buffer. --- src/block/get.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/block/get.js b/src/block/get.js index c30381893..f93539162 100644 --- a/src/block/get.js +++ b/src/block/get.js @@ -39,6 +39,7 @@ module.exports = (send) => { if (err) { return callback(err) } + if (!data.length) data = Buffer.alloc(0) callback(null, new Block(data, cid)) }) } From 429d56482dd49fb62c3a6fdbe06a578f63e95f20 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 21 Jun 2018 23:18:04 +0100 Subject: [PATCH 2/3] fix: get empty block for response without X-Stream-Output js-ipfs currently does not set the X-Stream-Output header on block.get responses so we also need a check for an empty array on our buffered res. License: MIT Signed-off-by: Alan Shaw --- src/block/get.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/block/get.js b/src/block/get.js index f93539162..327b9e7ff 100644 --- a/src/block/get.js +++ b/src/block/get.js @@ -34,11 +34,17 @@ module.exports = (send) => { const transform = (res, callback) => { if (Buffer.isBuffer(res)) { callback(null, new Block(res, cid)) + // For empty blocks, concat-stream can't infer the encoding so we are + // passed back an empty array + } else if (Array.isArray(res) && res.length === 0) { + callback(null, new Block(Buffer.alloc(0), cid)) } else { streamToValue(res, (err, data) => { if (err) { return callback(err) } + // For empty blocks, concat-stream can't infer the encoding so we are + // passed back an empty array if (!data.length) data = Buffer.alloc(0) callback(null, new Block(data, cid)) }) From 23a4b9e4884341c3c60f2057e91ad6cadce31d22 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 22 Jun 2018 10:24:50 +0100 Subject: [PATCH 3/3] chore: update to latest interface-ipfs-core License: MIT Signed-off-by: Alan Shaw --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aa058a8de..c335002b1 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "eslint-plugin-react": "^7.9.1", "go-ipfs-dep": "~0.4.15", "gulp": "^3.9.1", - "interface-ipfs-core": "~0.68.1", + "interface-ipfs-core": "~0.69.0", "ipfsd-ctl": "~0.37.3", "pull-stream": "^3.6.8", "socket.io": "^2.1.1",