Skip to content

Commit 8a017b3

Browse files
authored
Merge branch 'main' into dependabot/npm_and_yarn/aegir-47.0.16
2 parents ac71cde + 14d7e1c commit 8a017b3

File tree

6 files changed

+40
-3
lines changed

6 files changed

+40
-3
lines changed

packages/ipfs-unixfs-exporter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
"it-to-buffer": "^4.0.7",
169169
"merge-options": "^3.0.4",
170170
"readable-stream": "^4.5.2",
171-
"sinon": "^19.0.2",
171+
"sinon": "^21.0.0",
172172
"uint8arrays": "^5.1.0",
173173
"wherearewe": "^2.0.1"
174174
},

packages/ipfs-unixfs/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [ipfs-unixfs-v11.2.2](https://github.com/ipfs/js-ipfs-unixfs/compare/ipfs-unixfs-11.2.1...ipfs-unixfs-11.2.2) (2025-06-16)
2+
3+
### Bug Fixes
4+
5+
* limit incoming hamt width ([#433](https://github.com/ipfs/js-ipfs-unixfs/issues/433)) ([8ca0144](https://github.com/ipfs/js-ipfs-unixfs/commit/8ca014420094be90b8bb765bb3f703a9ce7260b1))
6+
17
## [ipfs-unixfs-v11.2.1](https://github.com/ipfs/js-ipfs-unixfs/compare/ipfs-unixfs-11.2.0...ipfs-unixfs-11.2.1) (2025-03-06)
28

39
### Dependencies

packages/ipfs-unixfs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ipfs-unixfs",
3-
"version": "11.2.1",
3+
"version": "11.2.2",
44
"description": "JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)",
55
"license": "Apache-2.0 OR MIT",
66
"homepage": "https://github.com/ipfs/js-ipfs-unixfs/tree/main/packages/ipfs-unixfs#readme",

packages/ipfs-unixfs/src/errors.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ export class InvalidTypeError extends Error {
88
super(message)
99
}
1010
}
11+
12+
export class InvalidUnixFSMessageError extends Error {
13+
static name = 'InvalidUnixFSMessageError'
14+
static code = 'ERR_INVALID_MESSAGE'
15+
name = InvalidUnixFSMessageError.name
16+
code = InvalidUnixFSMessageError.code
17+
18+
constructor (message = 'Invalid message') {
19+
super(message)
20+
}
21+
}

packages/ipfs-unixfs/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
* ```
9191
*/
9292

93-
import { InvalidTypeError } from './errors.js'
93+
import { InvalidTypeError, InvalidUnixFSMessageError } from './errors.js'
9494
import { Data as PBData } from './unixfs.js'
9595

9696
export interface Mtime {
@@ -117,6 +117,9 @@ const dirTypes = [
117117
const DEFAULT_FILE_MODE = parseInt('0644', 8)
118118
const DEFAULT_DIRECTORY_MODE = parseInt('0755', 8)
119119

120+
// https://github.com/ipfs/boxo/blob/364c5040ec91ec8e2a61446e9921e9225704c34d/ipld/unixfs/hamt/hamt.go#L778
121+
const MAX_FANOUT = BigInt(1 << 10)
122+
120123
export interface UnixFSOptions {
121124
type?: string
122125
data?: Uint8Array
@@ -134,6 +137,10 @@ class UnixFS {
134137
static unmarshal (marshaled: Uint8Array): UnixFS {
135138
const message = PBData.decode(marshaled)
136139

140+
if (message.fanout != null && message.fanout > MAX_FANOUT) {
141+
throw new InvalidUnixFSMessageError(`Fanout size was too large - ${message.fanout} > ${MAX_FANOUT}`)
142+
}
143+
137144
const data = new UnixFS({
138145
type: types[message.Type != null ? message.Type.toString() : 'File'],
139146
data: message.Data,

packages/ipfs-unixfs/test/unixfs-format.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,4 +431,17 @@ describe('unixfs-format', () => {
431431

432432
expect(marshaled).to.deep.equal(Uint8Array.from([0x08, 0x02, 0x18, 0x00]))
433433
})
434+
435+
it('should limit maximum fanout size', () => {
436+
const data = new UnixFS({
437+
type: 'hamt-sharded-directory',
438+
fanout: 1025n
439+
})
440+
const marshaled = data.marshal()
441+
442+
expect(() => {
443+
UnixFS.unmarshal(marshaled)
444+
}).to.throw()
445+
.with.property('name', 'InvalidUnixFSMessageError')
446+
})
434447
})

0 commit comments

Comments
 (0)