mirror of
https://github.com/ferdzo/fs.git
synced 2026-06-04 05:06:46 +00:00
Verify chunk integrity on read
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -17,6 +17,8 @@ import (
|
||||
const blobRoot = "blobs"
|
||||
const maxChunkSize = 64 * 1024 * 1024
|
||||
|
||||
var ErrChunkIntegrity = errors.New("chunk integrity check failed")
|
||||
|
||||
type BlobStore struct {
|
||||
dataRoot string
|
||||
chunkSize int
|
||||
@@ -185,6 +187,11 @@ func (bs *BlobStore) GetBlob(chunkID string) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chunkHash := sha256.Sum256(data)
|
||||
actualChunkID := hex.EncodeToString(chunkHash[:])
|
||||
if actualChunkID != chunkID {
|
||||
return nil, fmt.Errorf("%w: expected %s, got %s", ErrChunkIntegrity, chunkID, actualChunkID)
|
||||
}
|
||||
size = int64(len(data))
|
||||
success = true
|
||||
return data, nil
|
||||
|
||||
Reference in New Issue
Block a user