fs: fix panic when using --metadata-mapper on large google doc files

Before this change, attempting to copy a large google doc while using
the metadata mapper caused a panic. Google doc files use Rcat to
download as they have an unknown size, and when the size of the doc
file got above --streaming-upload-cutoff it used a
object.NewStaticObjectInfo with a `nil` Fs to upload the file which
caused the crash in the metadata mapper code.

This change makes sure that the Fs in object.NewStaticObjectInfo is
never nil, and it returns MemoryFs which is consistent with the Rcat
code when the source is sized below the --streaming-upload-cutoff
threshold.

Fixes #7845
This commit is contained in:
Nick Craig-Wood 2024-05-15 15:55:05 +01:00
parent b059c96322
commit 488ed28635
2 changed files with 4 additions and 0 deletions

View File

@ -43,6 +43,9 @@ func NewStaticObjectInfo(remote string, modTime time.Time, size int64, storable
info.hashes[ht] = "" info.hashes[ht] = ""
} }
} }
if f == nil {
info.fs = MemoryFs
}
return info return info
} }

View File

@ -34,6 +34,7 @@ func TestStaticObject(t *testing.T) {
o = object.NewStaticObjectInfo(remote, now, size, true, nil, nil) o = object.NewStaticObjectInfo(remote, now, size, true, nil, nil)
_, err = o.Hash(context.Background(), hash.MD5) _, err = o.Hash(context.Background(), hash.MD5)
assert.Equal(t, hash.ErrUnsupported, err) assert.Equal(t, hash.ErrUnsupported, err)
assert.Equal(t, object.MemoryFs, o.Fs())
hs := map[hash.Type]string{ hs := map[hash.Type]string{
hash.MD5: "potato", hash.MD5: "potato",