Commit aeb0568c authored by David Vorick's avatar David Vorick

add sanity check to file.open, check for consistent pubkey table

parent 7da74579
Pipeline #47424865 failed with stages
in 2 minutes and 25 seconds
......@@ -718,7 +718,7 @@ func (sf *SiaFile) goodPieces(chunkIndex int, offlineMap map[string]bool, goodFo
pktLen := len(sf.pubKeyTable)
hto := int(piece.HostTableOffset)
if hto >= pktLen {
build.Critical("Requesting a host that is outside the pubKeyTable", pktLen, hto)
build.Critical("Requesting a host that is outside the pubKeyTable", pktLen, hto, sf.Deleted)
continue
}
offline, exists1 := offlineMap[sf.pubKeyTable[piece.HostTableOffset].PublicKey.String()]
......
......@@ -171,6 +171,20 @@ func (sfs *SiaFileSet) open(siaPath string) (*SiaFileSetEntry, error) {
if entry.Deleted() {
return nil, ErrUnknownPath
}
// Sanity check - as we open the file, check that the pubKeyTable is
// consistent with the lookups in the pieces.
if build.Debug {
for i := 0; i < len(entry.staticChunks); i++ {
for j := 0; j < len(entry.staticChunks[i].Pieces); j++ {
for k := 0; k < len(entry.staticChunks[i].Pieces[j]); k++ {
if entry.staticChunks[i].Pieces[j][k] >= len(entry.pubKeyTable) {
build.Critical("Piece mismatch:", entry.staticChunks[i].Pieces[j][k], len(entry.pubKeyTable))
}
}
}
}
threadUID := randomThreadUID()
entry.threadMapMu.Lock()
defer entry.threadMapMu.Unlock()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment