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

Commit

Permalink
fix: make sure errors from unmarshalling are caught
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Oct 12, 2018
1 parent 12ecf51 commit 8b2335c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/exporter/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ module.exports = (cid, node, name, path, pathRest, resolve, size, dag, parent, d
return pull.empty()
}

const file = UnixFS.unmarshal(node.data)
let file

try {
file = UnixFS.unmarshal(node.data)
} catch (error) {
return pull.error(error)
}

const fileSize = size || file.fileSize()

if (offset < 0) {
Expand Down Expand Up @@ -103,7 +110,14 @@ function streamBytes (dag, node, fileSize, offset, length) {
return pull.empty()
}

const file = UnixFS.unmarshal(node.data)
let file

try {
file = UnixFS.unmarshal(node.data)
} catch (error) {
return pull.error(error)
}

const nodeHasData = Boolean(file.data && file.data.length)

// handle case where data is present on leaf nodes and internal nodes
Expand Down
10 changes: 9 additions & 1 deletion src/exporter/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function createResolver (dag, options, depth, parent) {
if (err) {
return cb(err)
}

// const name = item.fromPathRest ? item.name : item.path
cb(null, resolveItem(cid, node.value, item, options.offset, options.length))
})
Expand All @@ -57,7 +58,14 @@ function createResolver (dag, options, depth, parent) {
}

function resolve (cid, node, name, path, pathRest, size, dag, parentNode, depth, offset, length) {
const type = typeOf(node)
let type

try {
type = typeOf(node)
} catch (error) {
return pull.error(error)
}

const nodeResolver = resolvers[type]
if (!nodeResolver) {
return pull.error(new Error('Unkown node type ' + type))
Expand Down

0 comments on commit 8b2335c

Please sign in to comment.