[#1492] metabase: Ensure Unmarshal() is called on a cloned slice

The slice returned from bucket.Get() is only valid during the tx
lifetime. Cloning it is not necessary everywhere, but better safe than
sorry.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-11-13 10:07:32 +03:00 committed by Evgenii Stratonikov
parent b451de94c8
commit 8ed7a676d5
5 changed files with 10 additions and 7 deletions

View file

@ -1,6 +1,7 @@
package meta
import (
"bytes"
"context"
"errors"
"fmt"
@ -195,7 +196,7 @@ func iteratePhyObjects(tx *bbolt.Tx, f func(cid.ID, oid.ID, *objectSDK.Object) e
}
return b.ForEach(func(k, v []byte) error {
if oid.Decode(k) == nil && obj.Unmarshal(v) == nil {
if oid.Decode(k) == nil && obj.Unmarshal(bytes.Clone(v)) == nil {
return f(cid, oid, obj)
}