Skip to content

Commit f4cd7a1

Browse files
authored
fix(queryresult): check location claim shard multihash (#272)
# Goals Ooops... yea all we're doing for compressed queries is looking for a locaiton claim, but not checking its for the right shard. When there are multiple, bad things happen
1 parent 6910d74 commit f4cd7a1

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

pkg/service/queryresult/queryresult.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func BuildCompressed(targetMh mh.Multihash, principal ucan.Signer, claims map[ci
179179
}
180180

181181
for _, index := range indexes.Iterator() {
182-
for _, shard := range index.Shards().Iterator() {
182+
for shardHash, shard := range index.Shards().Iterator() {
183183
if shard.Has(targetMh) {
184184
pos := shard.Get(targetMh)
185185
hasLocation := false
@@ -190,6 +190,10 @@ func BuildCompressed(targetMh mh.Multihash, principal ucan.Signer, claims map[ci
190190
if err != nil {
191191
continue
192192
}
193+
if match.Value().Nb().Content.Hash().B58String() != shardHash.B58String() {
194+
continue
195+
}
196+
193197
hasLocation = true
194198

195199
locClaim = match.Value().Nb()

pkg/service/queryresult/queryresult_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,29 @@ func TestBuildCompressed(t *testing.T) {
7474
)
7575
require.NoError(t, err)
7676

77+
otherLocationURL, err := url.Parse("https://example2.com/shard.car")
78+
require.NoError(t, err)
79+
otherShardMH := testutil.RandomMultihash(t)
80+
otherShardLength := uint64(8000)
81+
otherShardClaim, err := assert.Location.Delegate(
82+
principal,
83+
principal,
84+
principal.DID().String(),
85+
assert.LocationCaveats{
86+
Content: ctypes.FromHash(otherShardMH),
87+
Location: []url.URL{*otherLocationURL},
88+
Range: &assert.Range{
89+
Offset: 1000, // The shard starts at offset 1000
90+
Length: &otherShardLength,
91+
},
92+
},
93+
)
94+
require.NoError(t, err)
95+
7796
// Build the claims map
7897
claims := map[cid.Cid]delegation.Delegation{
79-
link.ToCID(shardClaim.Link()): shardClaim,
98+
link.ToCID(otherShardClaim.Link()): otherShardClaim,
99+
link.ToCID(shardClaim.Link()): shardClaim,
80100
}
81101

82102
// Build the indexes map

0 commit comments

Comments
 (0)