Skip to content

Commit

Permalink
feat(launcher): Add CRC check after download
Browse files Browse the repository at this point in the history
  • Loading branch information
cedws committed Nov 24, 2024
1 parent 5b652e2 commit 0524169
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/umbra/umbra.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,21 @@ func (p *patchClient) checkFile(ctx context.Context, patchFile patchFile) error
}
defer file.Close()

if _, err := io.Copy(file, resp); err != nil {
hasher := p.hasherPool.Get().(*reverseHasher)
defer p.hasherPool.Put(hasher)

hasher.Reset()

teeReader := io.TeeReader(resp, hasher)
if _, err := io.Copy(file, teeReader); err != nil {
return err
}

actualCRC := hasher.Sum32()
if actualCRC != patchFile.CRC {
return fmt.Errorf("crc mismatch for file %s: expected %d, got %d", patchFile.Target, patchFile.CRC, actualCRC)
}

return nil
}

Expand Down

0 comments on commit 0524169

Please sign in to comment.