From b148b85af43586c8bba7d56fd8ac63ef8a6f9a90 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 14 Oct 2021 20:25:16 +0300 Subject: [PATCH] [#919] pkg/object: Do not accept objects with empty owner Signed-off-by: Pavel Karpy --- CHANGELOG.md | 1 + pkg/core/object/fmt.go | 44 ++++++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf5997323..8f243022f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Storage Node envs. command (#810) - SN and IR notary deposits are made dynamically depending on the Notary and GAS balances now (#873) +- Do not accept objects with empty owner (#841) ## [0.25.1] - 2021-09-29 diff --git a/pkg/core/object/fmt.go b/pkg/core/object/fmt.go index b0741e154..a734aebde 100644 --- a/pkg/core/object/fmt.go +++ b/pkg/core/object/fmt.go @@ -76,23 +76,28 @@ func (v *FormatValidator) Validate(obj *Object) error { return errNilCID } - for ; obj != nil; obj = obj.GetParent() { - if err := v.checkAttributes(obj); err != nil { - return fmt.Errorf("invalid attributes: %w", err) - } + if err := v.checkOwner(obj); err != nil { + return err + } - if err := v.validateSignatureKey(obj); err != nil { - return fmt.Errorf("(%T) could not validate signature key: %w", v, err) - } + if err := v.checkAttributes(obj); err != nil { + return fmt.Errorf("invalid attributes: %w", err) + } - // TODO: combine small checks - if err := v.checkExpiration(obj); err != nil { - return fmt.Errorf("object did not pass expiration check: %w", err) - } + if err := v.validateSignatureKey(obj); err != nil { + return fmt.Errorf("(%T) could not validate signature key: %w", v, err) + } - if err := object.CheckHeaderVerificationFields(obj.SDK()); err != nil { - return fmt.Errorf("(%T) could not validate header fields: %w", v, err) - } + if err := v.checkExpiration(obj); err != nil { + return fmt.Errorf("object did not pass expiration check: %w", err) + } + + if err := object.CheckHeaderVerificationFields(obj.SDK()); err != nil { + return fmt.Errorf("(%T) could not validate header fields: %w", v, err) + } + + if obj = obj.GetParent(); obj != nil { + return v.Validate(obj) } return nil @@ -258,6 +263,17 @@ func (v *FormatValidator) checkAttributes(obj *Object) error { return nil } +var errIncorrectOwner = errors.New("incorrect object owner") + +func (v *FormatValidator) checkOwner(obj *Object) error { + // TODO: use appropriate functionality after neofs-api-go#352 + if len(obj.OwnerID().ToV2().GetValue()) != owner.NEO3WalletSize { + return errIncorrectOwner + } + + return nil +} + // WithNetState returns options to set network state interface. // // FIXME: network state is a required parameter.