Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix: get block with empty data (#789)
Browse files Browse the repository at this point in the history
* 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.

* 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 <alan@tableflip.io>

* chore: update to latest interface-ipfs-core

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
  • Loading branch information
mikeal authored and alanshaw committed Jun 25, 2018
1 parent ad0a1da commit 88edd83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions src/block/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ 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))
})
}
Expand Down

0 comments on commit 88edd83

Please sign in to comment.