Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog for NeoFS Node

### Fixed
- Unclosed compressed FSTree files (#3802)
- Potential payload overflow on getting full object from combined FSTree file (#3801)

### Changed

Expand Down
48 changes: 48 additions & 0 deletions pkg/local_object_storage/blobstor/fstree/fstree_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package fstree

import (
"bytes"
"io"
"testing"
"testing/iotest"

"github.com/nspcc-dev/neofs-node/internal/testutil"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/compression"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -88,3 +92,47 @@ func testGetRangeStream(t *testing.T, fst *FSTree) {
_, err = fst.GetRangeStream(addr, 1, pldLen-1)
require.ErrorIs(t, err, apistatus.ErrObjectNotFound)
}

func TestFSTree_PutBatch(t *testing.T) {
t.Run("compressed", func(t *testing.T) {
fst := setupFSTree(t)

compCfg := &compression.Config{Enabled: true}
require.NoError(t, compCfg.Init())
fst.SetCompressor(compCfg)

testPutBatch(t, fst)
})

testPutBatch(t, setupFSTree(t))
}

func testPutBatch(t *testing.T, fst *FSTree) {
const pldLen = object.MaxHeaderLen

objs := make([]object.Object, 3)
batch := make(map[oid.Address][]byte)
for i := range objs {
objs[i] = objecttest.Object()
objs[i].SetPayloadSize(pldLen)
objs[i].SetPayload(testutil.RandByteSlice(pldLen))

batch[objs[i].Address()] = objs[i].Marshal()
}

require.NoError(t, fst.PutBatch(batch))

for i := range objs {
hdr, stream, err := fst.GetStream(objs[i].Address())
require.NoError(t, err)
t.Cleanup(func() { stream.Close() })

require.EqualValues(t, objs[i].CutPayload(), hdr)

// note: iotest.TestReader does not fit due to overridden io.Seeker interface
b, err := io.ReadAll(stream)
require.NoError(t, err)
require.Len(t, b, pldLen)
require.True(t, bytes.Equal(objs[i].Payload(), b))
}
}
9 changes: 9 additions & 0 deletions pkg/local_object_storage/blobstor/fstree/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ func (t *FSTree) extractHeaderAndStream(id oid.ID, f *os.File) (*object.Object,
return nil, f, fmt.Errorf("read up to size: %w", err)
}
}

f := io.ReadCloser(f)
if buffered := uint32(size - offset); l > buffered {
f = struct {
io.Reader
io.Closer
}{Reader: io.LimitReader(f, int64(l-buffered)), Closer: f}
}

return t.readHeaderAndPayload(f, buf[offset:size])
}

Expand Down
Loading