Package: python3-debian
Version: 1.1.1
Severity: normal

In Debusine, we ran into a case [1] where Deb822.merge_fields could 
raise ValueError if asked to merge two Binary fields of which one has 
been folded onto multiple lines and the other has not.  The attached 
test case reproduces this.

In general I think the merge_fields logic needs to be reworked to be 
properly aware of the possible field types [2].  It would seem better to 
me if it were explicitly told whether a field is simple, folded, or 
multiline, and then behaved accordingly.  Binary is defined to be folded 
[3], but for example [4] is not defined to be either folded or multiline 
and therefore is simple.

Relatedly, dpkg-source and dpkg-genchanges fold Binary across multiple 
lines if it is too long (see [5] and [6], and [7] for the original 
reason).  I think Deb822 should do the same when dumping this field.

[1] https://salsa.debian.org/freexian-team/debusine/-/work_items/1518
[2] 
https://www.debian.org/doc/debian-policy/ch-controlfields.html#syntax-of-control-files
[3] https://www.debian.org/doc/debian-policy/ch-controlfields.html#binary
[4] https://www.debian.org/doc/debian-policy/ch-controlfields.html#architecture
[5] 
https://git.dpkg.org/cgit/dpkg/dpkg.git/tree/scripts/dpkg-source.pl?h=1.23.7#n463
[6] 
https://git.dpkg.org/cgit/dpkg/dpkg.git/tree/scripts/dpkg-genchanges.pl?h=1.23.7#n491
[7] https://bugs.debian.org/494714

Thanks,

-- 
Colin Watson (he/him)                              [[email protected]]

-- System Information:
Debian Release: forky/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)
Foreign Architectures: arm64

Kernel: Linux 7.0.12+deb14.1-amd64 (SMP w/12 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_WARN, TAINT_OOT_MODULE
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_GB:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages python3-debian depends on:
ii  python3  3.13.9-3+b1

python3-debian recommends no packages.

Versions of packages python3-debian suggests:
ii  gpgv                        2.4.9-5
ii  python3-apt                 3.1.0
ii  python3-charset-normalizer  3.4.7-1
ii  zstd                        1.5.7+dfsg-3+b2

-- no debconf information
diff --git a/tests/test_deb822.py b/tests/test_deb822.py
index 8d1ddad..4484578 100755
--- a/tests/test_deb822.py
+++ b/tests/test_deb822.py
@@ -602,6 +602,21 @@ with open("test_deb822.pickle", "wb") as fh:
             " quux - package quux"
         )
 
+    def test_merge_fields_long_binary_field(self) -> None:
+        binaries = ("hello", *(f"hello-{i}" for i in range(110)))
+        left = deb822.Deb822({"Binary": binaries[0]})
+        right = deb822.Deb822(
+            {
+                "Binary": "\n ".join(
+                    (" ".join(binaries[1:110]), binaries[110])
+                )
+            }
+        )
+
+        left.merge_fields("Binary", right)
+
+        assert sorted(left["Binary"].split()) == sorted(binaries)
+
     def test_gpg_stripping(self) -> None:
         for string in GPG_SIGNED:
             unparsed_with_gpg = string % UNPARSED_PACKAGE

Reply via email to