From 67b3002743f056ab20abb0b5b59d520e6fe2a286 Mon Sep 17 00:00:00 2001
From: Anton Nikiforov <an.nikiforov@yadro.com>
Date: Thu, 6 Jun 2024 15:25:51 +0300
Subject: [PATCH] [#951] adm: Check for error when reading contracts from
 archive

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
---
 cmd/frostfs-adm/internal/modules/morph/helper/util.go | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/cmd/frostfs-adm/internal/modules/morph/helper/util.go b/cmd/frostfs-adm/internal/modules/morph/helper/util.go
index f0399ab377..ba557a0332 100644
--- a/cmd/frostfs-adm/internal/modules/morph/helper/util.go
+++ b/cmd/frostfs-adm/internal/modules/morph/helper/util.go
@@ -122,11 +122,11 @@ func readContractsFromArchive(file io.Reader, names []string) (map[string]*Contr
 	}
 
 	r := tar.NewReader(gr)
-	for h, err := r.Next(); ; h, err = r.Next() {
-		if err != nil {
-			break
+	var h *tar.Header
+	for h, err = r.Next(); err == nil && h != nil; h, err = r.Next() {
+		if h.Typeflag != tar.TypeReg {
+			continue
 		}
-
 		dir, _ := filepath.Split(h.Name)
 		ctrName := filepath.Base(dir)
 
@@ -149,6 +149,9 @@ func readContractsFromArchive(file io.Reader, names []string) (map[string]*Contr
 		}
 		m[ctrName] = cs
 	}
+	if err != nil && err != io.EOF {
+		return nil, fmt.Errorf("can't read contracts from archive: %w", err)
+	}
 
 	for ctrName, cs := range m {
 		if cs.RawNEF == nil {