Skip to content

Commit 59050ea

Browse files
authored
Merge pull request from GHSA-4gj3-6r43-3wfc
Add size check on the bitfield before allocation
2 parents 37b47f1 + e062cdb commit 59050ea

File tree

7 files changed

+162
-105
lines changed

7 files changed

+162
-105
lines changed

data/builder/dirshard.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,30 @@ func (s *shard) formatLinkName(name string, idx int) string {
133133
}
134134

135135
// bitmap calculates the bitmap of which links in the shard are set.
136-
func (s *shard) bitmap() []byte {
137-
bm := bitfield.NewBitfield(s.size)
136+
func (s *shard) bitmap() ([]byte, error) {
137+
bm, err := bitfield.NewBitfield(s.size)
138+
if err != nil {
139+
return nil, err
140+
}
138141
for i := 0; i < s.size; i++ {
139142
if _, ok := s.children[i]; ok {
140143
bm.SetBit(i)
141144
}
142145
}
143-
return bm.Bytes()
146+
return bm.Bytes(), nil
144147
}
145148

146149
// serialize stores the concrete representation of this shard in the link system and
147150
// returns a link to it.
148151
func (s *shard) serialize(ls *ipld.LinkSystem) (ipld.Link, uint64, error) {
152+
bm, err := s.bitmap()
153+
if err != nil {
154+
return nil, 0, err
155+
}
149156
ufd, err := BuildUnixFS(func(b *Builder) {
150157
DataType(b, data.Data_HAMTShard)
151158
HashType(b, s.hasher)
152-
Data(b, s.bitmap())
159+
Data(b, bm)
153160
Fanout(b, uint64(s.size))
154161
})
155162
if err != nil {

go.mod

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,70 @@ module github.com/ipfs/go-unixfsnode
33
go 1.19
44

55
require (
6-
github.com/ipfs/go-bitfield v1.0.0
7-
github.com/ipfs/go-cid v0.2.0
6+
github.com/ipfs/go-bitfield v1.1.0
7+
github.com/ipfs/go-cid v0.3.2
88
github.com/ipfs/go-ipfs-chunker v0.0.1
99
github.com/ipfs/go-ipfs-util v0.0.2
1010
github.com/ipfs/go-ipld-format v0.2.0
1111
github.com/ipfs/go-merkledag v0.5.1
12-
github.com/ipfs/go-unixfs v0.3.1
12+
github.com/ipfs/go-unixfs v0.4.3
1313
github.com/ipld/go-car/v2 v2.1.1
1414
github.com/ipld/go-codec-dagpb v1.4.1
1515
github.com/ipld/go-ipld-prime v0.16.0
16-
github.com/multiformats/go-multicodec v0.4.1
17-
github.com/multiformats/go-multihash v0.1.0
16+
github.com/multiformats/go-multicodec v0.7.0
17+
github.com/multiformats/go-multihash v0.2.1
1818
github.com/spaolacci/murmur3 v1.1.0
19-
github.com/stretchr/testify v1.7.0
20-
google.golang.org/protobuf v1.28.0
19+
github.com/stretchr/testify v1.8.1
20+
google.golang.org/protobuf v1.28.1
2121
)
2222

2323
require (
24+
github.com/benbjohnson/clock v1.3.0 // indirect
2425
github.com/davecgh/go-spew v1.1.1 // indirect
2526
github.com/gogo/protobuf v1.3.2 // indirect
26-
github.com/google/uuid v1.2.0 // indirect
27+
github.com/google/uuid v1.3.0 // indirect
2728
github.com/hashicorp/golang-lru v0.5.4 // indirect
2829
github.com/ipfs/bbloom v0.0.4 // indirect
2930
github.com/ipfs/go-block-format v0.0.3 // indirect
3031
github.com/ipfs/go-blockservice v0.2.1 // indirect
31-
github.com/ipfs/go-datastore v0.5.0 // indirect
32+
github.com/ipfs/go-datastore v0.6.0 // indirect
3233
github.com/ipfs/go-ipfs-blockstore v1.1.2 // indirect
3334
github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect
3435
github.com/ipfs/go-ipfs-exchange-interface v0.1.0 // indirect
3536
github.com/ipfs/go-ipfs-exchange-offline v0.1.1 // indirect
3637
github.com/ipfs/go-ipld-cbor v0.0.5 // indirect
3738
github.com/ipfs/go-ipld-legacy v0.1.0 // indirect
3839
github.com/ipfs/go-log v1.0.5 // indirect
39-
github.com/ipfs/go-log/v2 v2.3.0 // indirect
40+
github.com/ipfs/go-log/v2 v2.5.1 // indirect
4041
github.com/ipfs/go-metrics-interface v0.0.1 // indirect
4142
github.com/ipfs/go-verifcid v0.0.1 // indirect
4243
github.com/jbenet/goprocess v0.1.4 // indirect
43-
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
44-
github.com/libp2p/go-buffer-pool v0.0.2 // indirect
45-
github.com/mattn/go-isatty v0.0.13 // indirect
46-
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
44+
github.com/klauspost/cpuid/v2 v2.2.1 // indirect
45+
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
46+
github.com/libp2p/go-libp2p v0.25.0 // indirect
47+
github.com/mattn/go-isatty v0.0.16 // indirect
4748
github.com/minio/sha256-simd v1.0.0 // indirect
4849
github.com/mr-tron/base58 v1.2.0 // indirect
49-
github.com/multiformats/go-base32 v0.0.4 // indirect
50-
github.com/multiformats/go-base36 v0.1.0 // indirect
51-
github.com/multiformats/go-multibase v0.0.3 // indirect
52-
github.com/multiformats/go-varint v0.0.6 // indirect
50+
github.com/multiformats/go-base32 v0.1.0 // indirect
51+
github.com/multiformats/go-base36 v0.2.0 // indirect
52+
github.com/multiformats/go-multiaddr v0.8.0 // indirect
53+
github.com/multiformats/go-multibase v0.1.1 // indirect
54+
github.com/multiformats/go-varint v0.0.7 // indirect
5355
github.com/opentracing/opentracing-go v1.2.0 // indirect
5456
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 // indirect
5557
github.com/pmezard/go-difflib v1.0.0 // indirect
5658
github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e // indirect
5759
github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 // indirect
5860
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158 // indirect
5961
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect
60-
go.uber.org/atomic v1.7.0 // indirect
61-
go.uber.org/multierr v1.7.0 // indirect
62-
go.uber.org/zap v1.16.0 // indirect
63-
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f // indirect
64-
golang.org/x/exp v0.0.0-20210615023648-acb5c1269671 // indirect
65-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
66-
golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32 // indirect
62+
go.uber.org/atomic v1.10.0 // indirect
63+
go.uber.org/multierr v1.8.0 // indirect
64+
go.uber.org/zap v1.24.0 // indirect
65+
golang.org/x/crypto v0.4.0 // indirect
66+
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
67+
golang.org/x/sync v0.1.0 // indirect
68+
golang.org/x/sys v0.3.0 // indirect
6769
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
68-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
70+
gopkg.in/yaml.v3 v3.0.1 // indirect
6971
lukechampine.com/blake3 v1.1.7 // indirect
7072
)

0 commit comments

Comments
 (0)