mirror of
https://github.com/octoleo/restic.git
synced 2024-11-23 21:27:34 +00:00
repository: Better error message if blob is larger than 4GB
This commit is contained in:
parent
55d56db31b
commit
10355c3fb6
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -69,11 +70,9 @@ func (idx *Index) addToPacks(id restic.ID) int {
|
|||||||
return len(idx.packs) - 1
|
return len(idx.packs) - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxuint32 = 1<<32 - 1
|
|
||||||
|
|
||||||
func (idx *Index) store(packIndex int, blob restic.Blob) {
|
func (idx *Index) store(packIndex int, blob restic.Blob) {
|
||||||
// assert that offset and length fit into uint32!
|
// assert that offset and length fit into uint32!
|
||||||
if blob.Offset > maxuint32 || blob.Length > maxuint32 || blob.UncompressedLength > maxuint32 {
|
if blob.Offset > math.MaxUint32 || blob.Length > math.MaxUint32 || blob.UncompressedLength > math.MaxUint32 {
|
||||||
panic("offset or length does not fit in uint32. You have packs > 4GB!")
|
panic("offset or length does not fit in uint32. You have packs > 4GB!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
@ -917,6 +918,10 @@ func (r *Repository) Close() error {
|
|||||||
// occupies in the repo (compressed or not, including encryption overhead).
|
// occupies in the repo (compressed or not, including encryption overhead).
|
||||||
func (r *Repository) SaveBlob(ctx context.Context, t restic.BlobType, buf []byte, id restic.ID, storeDuplicate bool) (newID restic.ID, known bool, size int, err error) {
|
func (r *Repository) SaveBlob(ctx context.Context, t restic.BlobType, buf []byte, id restic.ID, storeDuplicate bool) (newID restic.ID, known bool, size int, err error) {
|
||||||
|
|
||||||
|
if int64(len(buf)) > math.MaxUint32 {
|
||||||
|
return restic.ID{}, false, 0, fmt.Errorf("blob is larger than 4GB")
|
||||||
|
}
|
||||||
|
|
||||||
// compute plaintext hash if not already set
|
// compute plaintext hash if not already set
|
||||||
if id.IsNull() {
|
if id.IsNull() {
|
||||||
// Special case the hash calculation for all zero chunks. This is especially
|
// Special case the hash calculation for all zero chunks. This is especially
|
||||||
|
Loading…
Reference in New Issue
Block a user