fix: Use offset to prevent re-indexing encrypted headers

This commit is contained in:
Felix Pojtinger
2021-12-10 21:51:12 +01:00
parent 9516b7db2e
commit 734df25820
8 changed files with 48 additions and 50 deletions
+13 -2
View File
@@ -2,11 +2,13 @@ package operations
import (
"archive/tar"
"errors"
"io"
"io/fs"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/pojntfx/stfs/internal/compression"
"github.com/pojntfx/stfs/internal/converters"
@@ -22,6 +24,10 @@ import (
"github.com/pojntfx/stfs/pkg/config"
)
var (
errSocketsNotSupported = errors.New("archive/tar: sockets not supported")
)
func Archive(
state config.StateConfig,
pipes config.PipeConfig,
@@ -107,6 +113,11 @@ func Archive(
hdr, err := tar.FileInfoHeader(info, link)
if err != nil {
// Skip sockets
if strings.Contains(err.Error(), errSocketsNotSupported.Error()) {
return nil
}
return err
}
@@ -220,6 +231,8 @@ func Archive(
return err
}
dirty = true
if !info.Mode().IsRegular() {
return nil
}
@@ -273,8 +286,6 @@ func Archive(
return err
}
dirty = true
return nil
})
}
+3 -7
View File
@@ -106,18 +106,14 @@ func Delete(
int(lastIndexedRecord),
int(lastIndexedBlock),
false,
1, // Ignore the first header, which is the last header which we already indexed
func(hdr *tar.Header, i int) error {
// Ignore the first header, which is the last header which we already indexed
if i == 0 {
return nil
}
if len(hdrs) <= i-1 {
if len(hdrs) <= i {
return config.ErrTarHeaderMissing
}
*hdr = *hdrs[i-1]
*hdr = *hdrs[i]
return nil
},
+3 -7
View File
@@ -110,18 +110,14 @@ func Move(
int(lastIndexedRecord),
int(lastIndexedBlock),
false,
1, // Ignore the first header, which is the last header which we already indexed
func(hdr *tar.Header, i int) error {
// Ignore the first header, which is the last header which we already indexed
if i == 0 {
return nil
}
if len(hdrs) <= i-1 {
if len(hdrs) <= i {
return config.ErrTarHeaderMissing
}
*hdr = *hdrs[i-1]
*hdr = *hdrs[i]
return nil
},
+21 -16
View File
@@ -31,6 +31,7 @@ func Index(
record int,
block int,
overwrite bool,
offset int,
decryptHeader func(
hdr *tar.Header,
@@ -129,16 +130,18 @@ func Index(
break
}
if err := decryptHeader(hdr, i); err != nil {
return err
}
if i >= offset {
if err := decryptHeader(hdr, i-offset); err != nil {
return err
}
if err := verifyHeader(hdr, isRegular); err != nil {
return err
}
if err := verifyHeader(hdr, isRegular); err != nil {
return err
}
if err := indexHeader(record, block, hdr, metadataPersister, pipes.Compression, pipes.Encryption, onHeader); err != nil {
return err
if err := indexHeader(record, block, hdr, metadataPersister, pipes.Compression, pipes.Encryption, onHeader); err != nil {
return err
}
}
curr, err := f.Seek(0, io.SeekCurrent)
@@ -213,16 +216,18 @@ func Index(
}
}
if err := decryptHeader(hdr, i); err != nil {
return err
}
if i >= offset {
if err := decryptHeader(hdr, i-offset); err != nil {
return err
}
if err := verifyHeader(hdr, isRegular); err != nil {
return err
}
if err := verifyHeader(hdr, isRegular); err != nil {
return err
}
if err := indexHeader(record, block, hdr, metadataPersister, pipes.Compression, pipes.Encryption, onHeader); err != nil {
return err
if err := indexHeader(record, block, hdr, metadataPersister, pipes.Compression, pipes.Encryption, onHeader); err != nil {
return err
}
}
curr = int64(counter.BytesRead)