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

Commit 8b2335c

Browse files
committed
fix: make sure errors from unmarshalling are caught
1 parent 12ecf51 commit 8b2335c

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/exporter/file.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ module.exports = (cid, node, name, path, pathRest, resolve, size, dag, parent, d
1515
return pull.empty()
1616
}
1717

18-
const file = UnixFS.unmarshal(node.data)
18+
let file
19+
20+
try {
21+
file = UnixFS.unmarshal(node.data)
22+
} catch (error) {
23+
return pull.error(error)
24+
}
25+
1926
const fileSize = size || file.fileSize()
2027

2128
if (offset < 0) {
@@ -103,7 +110,14 @@ function streamBytes (dag, node, fileSize, offset, length) {
103110
return pull.empty()
104111
}
105112

106-
const file = UnixFS.unmarshal(node.data)
113+
let file
114+
115+
try {
116+
file = UnixFS.unmarshal(node.data)
117+
} catch (error) {
118+
return pull.error(error)
119+
}
120+
107121
const nodeHasData = Boolean(file.data && file.data.length)
108122

109123
// handle case where data is present on leaf nodes and internal nodes

src/exporter/resolve.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function createResolver (dag, options, depth, parent) {
4343
if (err) {
4444
return cb(err)
4545
}
46+
4647
// const name = item.fromPathRest ? item.name : item.path
4748
cb(null, resolveItem(cid, node.value, item, options.offset, options.length))
4849
})
@@ -57,7 +58,14 @@ function createResolver (dag, options, depth, parent) {
5758
}
5859

5960
function resolve (cid, node, name, path, pathRest, size, dag, parentNode, depth, offset, length) {
60-
const type = typeOf(node)
61+
let type
62+
63+
try {
64+
type = typeOf(node)
65+
} catch (error) {
66+
return pull.error(error)
67+
}
68+
6169
const nodeResolver = resolvers[type]
6270
if (!nodeResolver) {
6371
return pull.error(new Error('Unkown node type ' + type))

0 commit comments

Comments
 (0)