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

Commit 7835215

Browse files
committed
Improve input checking on "add".
1 parent 29c2c83 commit 7835215

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"flatmap": "0.0.3",
1414
"glob": "^7.0.3",
1515
"ipfs-merkle-dag": "^0.6.0",
16+
"isstream": "^0.1.2",
1617
"multiaddr": "^2.0.0",
1718
"multipart-stream": "^2.0.1",
1819
"ndjson": "^1.4.3",

src/api/add.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const isStream = require('isstream')
34
const Wreck = require('wreck')
45
const addToDagNodesTransform = require('../add-to-dagnode-transform')
56

@@ -10,6 +11,14 @@ module.exports = (send) => {
1011
opts = {}
1112
}
1213

14+
var good = Buffer.isBuffer(files) ||
15+
isStream.isReadable(files) ||
16+
Array.isArray(files)
17+
18+
if (!good) {
19+
return cb(new Error('"files" must be a buffer, readable stream, or array of objects'))
20+
}
21+
1322
var sendWithTransform = send.withTransform(addToDagNodesTransform)
1423

1524
return sendWithTransform('add', null, opts, files, cb)

0 commit comments

Comments
 (0)