Package: dpkg-dev
Followup-For: Bug #1081434
X-Debbugs-Cc: [email protected]

Seeking beyond the patch header before spawning the system patch tool solves
this in all my local testing, including using Simon's example patch that
triggered this.
>From c84afc950bf485c42f76e98291682b3da6b9ff65 Mon Sep 17 00:00:00 2001
From: Tj <[email protected]>
Date: Sun, 2 Mar 2025 08:51:34 +0000
Subject: [PATCH 2/2] Source/Patch: fix patch tool applying header text

If a patch header quotes a complete patch hunk (indented) the system
patch tool will treat it as a valid hunk and attempt to apply it.

Since there is no way to prevent most patch tools doing that simply
don't pass the patch header to the system patch tool.

Signed-off-by: Tj <[email protected]>
---
 scripts/Dpkg/Source/Patch.pm | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/scripts/Dpkg/Source/Patch.pm b/scripts/Dpkg/Source/Patch.pm
index 124b88a94..1ab4a57dd 100644
--- a/scripts/Dpkg/Source/Patch.pm
+++ b/scripts/Dpkg/Source/Patch.pm
@@ -634,6 +634,7 @@ sub apply {
     $self->prepare_apply($analysis, %opts);
     # Apply the patch
     $self->ensure_open('r');
+    seek($self, length( $analysis->{patchheader} ), 0);
     my ($stdout, $stderr) = ('', '');
     spawn(
        exec => [ $Dpkg::PROGPATCH, @{$opts{options}} ],
@@ -695,6 +696,7 @@ sub check_apply {
     $self->prepare_apply($analysis, %opts);
     # Apply the patch
     $self->ensure_open('r');
+    seek($self, length( $analysis->{patchheader} ), 0);
     my $patch_pid = spawn(
        exec => [ $Dpkg::PROGPATCH, @{$opts{options}} ],
        chdir => $destdir,
-- 
2.39.5

Reply via email to