lib/model: Encrypted fileinfo trailer needs to be in wire format (#7505)

This commit is contained in:
Simon Frei
2021-03-21 10:34:08 +01:00
committed by GitHub
parent a87c5515bd
commit bc08a951f1
2 changed files with 15 additions and 4 deletions
+9 -3
View File
@@ -13,6 +13,7 @@ import (
"github.com/pkg/errors"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/sync"
)
@@ -346,8 +347,13 @@ func (s *sharedPullerState) finalClose() (bool, error) {
// folder from encrypted data we can extract this FileInfo from the end of
// the file and regain the original metadata.
func (s *sharedPullerState) finalizeEncrypted() error {
bs := make([]byte, encryptionTrailerSize(s.file))
n, err := s.file.MarshalTo(bs)
// Here the file is in native format, while encryption happens in
// wire format (always slashes).
wireFile := s.file
wireFile.Name = osutil.NormalizedFilename(wireFile.Name)
bs := make([]byte, encryptionTrailerSize(wireFile))
n, err := wireFile.MarshalTo(bs)
if err != nil {
return err
}
@@ -359,7 +365,7 @@ func (s *sharedPullerState) finalizeEncrypted() error {
return err
}
}
if _, err := s.writer.WriteAt(bs, s.file.Size); err != nil {
if _, err := s.writer.WriteAt(bs, wireFile.Size); err != nil {
return err
}