mirror of
https://github.com/restic/restic.git
synced 2024-12-23 16:26:11 +00:00
pack: Handle small files
This commit is contained in:
parent
92c0aa3854
commit
eb767ab15f
1 changed files with 26 additions and 0 deletions
|
@ -189,9 +189,26 @@ func readHeaderLength(rd io.ReaderAt, size int64) (uint32, error) {
|
||||||
|
|
||||||
const maxHeaderSize = 16 * 1024 * 1024
|
const maxHeaderSize = 16 * 1024 * 1024
|
||||||
|
|
||||||
|
// we require at least one entry in the header, and one blob for a pack file
|
||||||
|
var minFileSize = entrySize + crypto.Extension
|
||||||
|
|
||||||
// readHeader reads the header at the end of rd. size is the length of the
|
// readHeader reads the header at the end of rd. size is the length of the
|
||||||
// whole data accessible in rd.
|
// whole data accessible in rd.
|
||||||
func readHeader(rd io.ReaderAt, size int64) ([]byte, error) {
|
func readHeader(rd io.ReaderAt, size int64) ([]byte, error) {
|
||||||
|
if size == 0 {
|
||||||
|
err := InvalidFileError{
|
||||||
|
Message: "file is empty",
|
||||||
|
}
|
||||||
|
return nil, errors.Wrap(err, "readHeader")
|
||||||
|
}
|
||||||
|
|
||||||
|
if size < int64(minFileSize) {
|
||||||
|
err := InvalidFileError{
|
||||||
|
Message: "file is too small",
|
||||||
|
}
|
||||||
|
return nil, errors.Wrap(err, "readHeader")
|
||||||
|
}
|
||||||
|
|
||||||
hl, err := readHeaderLength(rd, size)
|
hl, err := readHeaderLength(rd, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -218,6 +235,15 @@ func readHeader(rd io.ReaderAt, size int64) ([]byte, error) {
|
||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InvalidFileError is return when a file is found that is not a pack file.
|
||||||
|
type InvalidFileError struct {
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e InvalidFileError) Error() string {
|
||||||
|
return e.Message
|
||||||
|
}
|
||||||
|
|
||||||
// List returns the list of entries found in a pack file.
|
// List returns the list of entries found in a pack file.
|
||||||
func List(k *crypto.Key, rd io.ReaderAt, size int64) (entries []restic.Blob, err error) {
|
func List(k *crypto.Key, rd io.ReaderAt, size int64) (entries []restic.Blob, err error) {
|
||||||
buf, err := readHeader(rd, size)
|
buf, err := readHeader(rd, size)
|
||||||
|
|
Loading…
Reference in a new issue