From 710654d64947908e4424c1e71d3e998d97ac08a3 Mon Sep 17 00:00:00 2001
From: Tomas Kopecek <tkopecek@redhat.com>
Date: Mar 02 2023 14:46:05 +0000
Subject: [PATCH 1/4] RawHeader.get can return also string lists


Related: https://pagure.io/koji/issue/3713

---

diff --git a/koji/__init__.py b/koji/__init__.py
index 024a8c5..2490b7f 100644
--- a/koji/__init__.py
+++ b/koji/__init__.py
@@ -807,6 +807,14 @@ class RawHeader(object):
         elif dtype == 7:
             # raw data
             return self.header[pos:pos + count]
+        elif dtype == 8:
+            # string array
+            result = []
+            for i in range(count):
+                end = self.header.find(six.b('\0'), pos)
+                result.append(self.header[pos:end])
+                pos = end + 1
+            return result
         else:
             # XXX - not all valid data types are handled
             raise GenericError("Unable to read header data type: %x" % dtype)

From 8593f418f69ae37ec060dd12d00ef0ce721e14f6 Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Mar 02 2023 14:46:05 +0000
Subject: [PATCH 2/4] also support get for unicode string arrays


---

diff --git a/koji/__init__.py b/koji/__init__.py
index 2490b7f..e88a677 100644
--- a/koji/__init__.py
+++ b/koji/__init__.py
@@ -770,7 +770,11 @@ class RawHeader(object):
                 # unicode string array
                 for i in range(count):
                     end = self.header.find(six.b('\0'), pos)
-                    print("i18n(%d): %r" % (end - pos, self.header[pos:end]))
+                    try:
+                        print("i18n(%d): %r" % (end - pos, _decode_item(self.header[pos:end])))
+                    except Exception:
+                        print('INVALID STRING')
+                        print("i18n(%d): %r" % (end - pos, self.header[pos:end]))
                     pos = end + 1
                 next = pos
             else:
@@ -815,6 +819,14 @@ class RawHeader(object):
                 result.append(self.header[pos:end])
                 pos = end + 1
             return result
+        elif dtype == 9:
+            # unicode string array
+            result = []
+            for i in range(count):
+                end = self.header.find(six.b('\0'), pos)
+                result.append(_decode_item(self.header[pos:end]))
+                pos = end + 1
+            return result
         else:
             # XXX - not all valid data types are handled
             raise GenericError("Unable to read header data type: %x" % dtype)

From 93f89b07a79400b1aefab6da60cc9341ec972145 Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Mar 02 2023 14:46:05 +0000
Subject: [PATCH 3/4] attempt to decode strings in dump


---

diff --git a/koji/__init__.py b/koji/__init__.py
index e88a677..d0fece3 100644
--- a/koji/__init__.py
+++ b/koji/__init__.py
@@ -754,7 +754,12 @@ class RawHeader(object):
             elif dtype == 6:
                 # string (null terminated)
                 end = self.header.find(six.b('\0'), pos)
-                print("String(%d): %r" % (end - pos, self.header[pos:end]))
+                try:
+                    print("String(%d): %r" % (end - pos, _decode_item(self.header[pos:end])))
+                except ValueError:
+                    print('INVALID STRING')
+                    print("String(%d): %r" % (end - pos, self.header[pos:end]))
+                    raise
                 next = end + 1
             elif dtype == 7:
                 print("Data: %s" % hex_string(self.header[pos:pos + count]))

From 397e525591f3693ab33c3f2b9ccbaec3a57aa751 Mon Sep 17 00:00:00 2001
From: Tomas Kopecek <tkopecek@redhat.com>
Date: Mar 02 2023 14:48:36 +0000
Subject: [PATCH 4/4] flake8 fix


---

diff --git a/koji/__init__.py b/koji/__init__.py
index d0fece3..29e7f7f 100644
--- a/koji/__init__.py
+++ b/koji/__init__.py
@@ -819,7 +819,7 @@ class RawHeader(object):
         elif dtype == 8:
             # string array
             result = []
-            for i in range(count):
+            for _ in range(count):
                 end = self.header.find(six.b('\0'), pos)
                 result.append(self.header[pos:end])
                 pos = end + 1
@@ -827,7 +827,7 @@ class RawHeader(object):
         elif dtype == 9:
             # unicode string array
             result = []
-            for i in range(count):
+            for _ in range(count):
                 end = self.header.find(six.b('\0'), pos)
                 result.append(_decode_item(self.header[pos:end]))
                 pos = end + 1

