From 72e2bc8fb6c6c0c67fd8ebf0786ade6b1970985f Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 18 May 2021 15:13:40 +0300 Subject: [PATCH] [#532] object/hash: Fix NPE during request forwarding In current implementation `Object.GetRangeHash` RPC handler forwards range requests for payload data. Missing request forwarder of the original request caused NPE during execution. Do not call request forwarder if payload range hash is requested. Signed-off-by: Leonard Lyubich --- pkg/services/object/get/exec.go | 12 +++++++++++- pkg/services/object/get/get.go | 8 ++++++-- pkg/services/object/get/util.go | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/services/object/get/exec.go b/pkg/services/object/get/exec.go index 4752e60b76..140ece9f66 100644 --- a/pkg/services/object/get/exec.go +++ b/pkg/services/object/get/exec.go @@ -38,7 +38,7 @@ type execCtx struct { curOff uint64 - head bool + head, hash bool curProcEpoch uint64 @@ -71,6 +71,12 @@ func withPayloadRange(r *objectSDK.Range) execOption { } } +func hashOnly() execOption { + return func(c *execCtx) { + c.hash = true + } +} + func (exec *execCtx) setLogger(l *logger.Logger) { req := "GET" if exec.headOnly() { @@ -146,6 +152,10 @@ func (exec *execCtx) headOnly() bool { return exec.head } +func (exec *execCtx) hashOnly() bool { + return exec.hash +} + func (exec *execCtx) netmapEpoch() uint64 { return exec.prm.common.NetmapEpoch() } diff --git a/pkg/services/object/get/get.go b/pkg/services/object/get/get.go index 43e7d50b6e..d7f230118c 100644 --- a/pkg/services/object/get/get.go +++ b/pkg/services/object/get/get.go @@ -15,7 +15,11 @@ func (s *Service) Get(ctx context.Context, prm Prm) error { // GetRange serves a request to get an object by address, and returns Streamer instance. func (s *Service) GetRange(ctx context.Context, prm RangePrm) error { - return s.get(ctx, prm.commonPrm, withPayloadRange(prm.rng)).err + return s.getRange(ctx, prm) +} + +func (s *Service) getRange(ctx context.Context, prm RangePrm, opts ...execOption) error { + return s.get(ctx, prm.commonPrm, append(opts, withPayloadRange(prm.rng))...).err } func (s *Service) GetRangeHash(ctx context.Context, prm RangeHashPrm) (*RangeHashRes, error) { @@ -37,7 +41,7 @@ func (s *Service) GetRangeHash(ctx context.Context, prm RangeHashPrm) (*RangeHas hash: util.NewSaltingWriter(h, prm.salt), }) - if err := s.GetRange(ctx, rngPrm); err != nil { + if err := s.getRange(ctx, rngPrm, hashOnly()); err != nil { return nil, err } diff --git a/pkg/services/object/get/util.go b/pkg/services/object/get/util.go index 3c992bd939..eb3316de11 100644 --- a/pkg/services/object/get/util.go +++ b/pkg/services/object/get/util.go @@ -80,7 +80,7 @@ func (c *clientCacheWrapper) get(addr string) (getClient, error) { } func (c *clientWrapper) getObject(exec *execCtx) (*objectSDK.Object, error) { - if !exec.assembling { + if !exec.assembling && !exec.hashOnly() { return exec.prm.forwarder(c.client) }