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

Commit c817f02

Browse files
achingbrainalanshaw
authored andcommitted
test: adds test vulnerable to encoding translation (#302)
1 parent 6065f63 commit c817f02

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

js/src/object/get.js

+36
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const bs58 = require('bs58')
77
const series = require('async/series')
88
const hat = require('hat')
99
const { getDescribe, getIt, expect } = require('../utils/mocha')
10+
const UnixFs = require('ipfs-unixfs')
11+
const crypto = require('crypto')
1012

1113
module.exports = (createCommon, options) => {
1214
const describe = getDescribe(options)
@@ -285,5 +287,39 @@ module.exports = (createCommon, options) => {
285287
}
286288
], done)
287289
})
290+
291+
it('supplies unadulterated data', () => {
292+
// has to be big enough to span several DAGNodes
293+
let required = 1024 * 3000
294+
295+
// can't just request `required` random bytes in the browser yet
296+
// as it's more than 65536:
297+
// https://github.com/crypto-browserify/randombytes/pull/15
298+
let data = Buffer.alloc(0)
299+
const maxBytes = 65536
300+
let next = maxBytes
301+
302+
while (data.length !== required) {
303+
data = Buffer.concat([data, crypto.randomBytes(next)])
304+
next = maxBytes
305+
306+
if (data.length + maxBytes > required) {
307+
next = required - data.length
308+
}
309+
}
310+
311+
return ipfs.files.add({
312+
path: '',
313+
content: data
314+
})
315+
.then((result) => {
316+
return ipfs.object.get(result[0].hash)
317+
})
318+
.then((node) => {
319+
const meta = UnixFs.unmarshal(node.data)
320+
321+
expect(meta.fileSize()).to.equal(data.length)
322+
})
323+
})
288324
})
289325
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"dirty-chai": "^2.0.1",
4343
"hat": "0.0.3",
4444
"ipfs-block": "~0.7.1",
45+
"ipfs-unixfs": "~0.1.15",
4546
"ipld-dag-cbor": "~0.12.1",
4647
"ipld-dag-pb": "~0.14.5",
4748
"is-ipfs": "~0.3.2",

0 commit comments

Comments
 (0)