Package: dpkg-dev Version: 1.21.22 Severity: normal File: /usr/bin/dpkg-source Tags: patch X-Debbugs-Cc: [email protected]
analyze() fails to correctly parse a patch header that has a line that matches two of the three hunk detection regular expressions because it treats them in isolation rather than as a linked, ordered, series. josch in IRC's #debian-mentors reported this error: dpkg-source: error: expected ^--- in line 7 of diff 'mesa-24.3.4.orig.JVu23i/debian/patches/mesa25/2079-radeonsi-fix-a-TCS-regression.patch' The cause being the isolated "@@ -" in the patch header that was directly taken from git-format-patch (here prefixed with "> " to avoid causing the same error!): > From a0579f75fb5aa6926f4acfdee3fa91f2666df559 Mon Sep 17 00:00:00 2001 > From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= <[email protected]> > Date: Tue, 24 Dec 2024 15:00:39 -0500 > Subject: [PATCH 2079/3849] radeonsi: fix a TCS regression > > This change caused the regression: > @@ -853,7 +853,7 @@ bool si_llvm_compile_shader(struct si_screen *sscreen, > struct ac_llvm_compiler * ... > > Reviewed-by: Qiang Yu <[email protected]> > Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32780> > --- > src/gallium/drivers/radeonsi/si_shader_llvm.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/src/gallium/drivers/radeonsi/si_shader_llvm.c > b/src/gallium/drivers/radeonsi/si_shader_llvm.c > index 620953e817f..bd0309744de 100644 > --- a/src/gallium/drivers/radeonsi/si_shader_llvm.c > +++ b/src/gallium/drivers/radeonsi/si_shader_llvm.c > @@ -840,12 +840,12 @@ bool si_llvm_compile_shader(struct si_screen *sscreen, > struct ac_llvm_compiler * > struct si_shader prev_shader = {}; My patch revises the parsing logic to treat the three hunk markers as ordered and linked.
>From f6cbe0c3e240e66e8ad71a4003068b7b1fdf413a Mon Sep 17 00:00:00 2001 From: Tj <[email protected]> Date: Sat, 1 Mar 2025 07:27:23 +0000 Subject: [PATCH] Source/Patch: fix parsing of patch header analyze() failed to correctly parse a patch header that has a line that matches two of the three hunk detection regular expressions because it treats them in isolation rather than as a linked, ordered, series. josch in IRC's #debian-mentors reported this error: dpkg-source: error: expected ^--- in line 7 of diff 'mesa-24.3.4.orig.JVu23i/debian/patches/mesa25/2079-radeonsi-fix-a-TCS-regression.patch' The cause being the isolated "@@ -" in the patch header that was directly taken from git-format-patch (here prefixed with "> " to avoid causing the same error!): > From a0579f75fb5aa6926f4acfdee3fa91f2666df559 Mon Sep 17 00:00:00 2001 > From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= <[email protected]> > Date: Tue, 24 Dec 2024 15:00:39 -0500 > Subject: [PATCH 2079/3849] radeonsi: fix a TCS regression > > This change caused the regression: > @@ -853,7 +853,7 @@ bool si_llvm_compile_shader(struct si_screen *sscreen, > struct ac_llvm_compiler * ... > > Reviewed-by: Qiang Yu <[email protected]> > Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32780> > --- > src/gallium/drivers/radeonsi/si_shader_llvm.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/src/gallium/drivers/radeonsi/si_shader_llvm.c > b/src/gallium/drivers/radeonsi/si_shader_llvm.c > index 620953e817f..bd0309744de 100644 > --- a/src/gallium/drivers/radeonsi/si_shader_llvm.c > +++ b/src/gallium/drivers/radeonsi/si_shader_llvm.c > @@ -840,12 +840,12 @@ bool si_llvm_compile_shader(struct si_screen *sscreen, > struct ac_llvm_compiler * > struct si_shader prev_shader = {}; Revise the parsing logic to treat the three hunk markers as ordered and linked. Signed-off-by: Tj <[email protected]> --- scripts/Dpkg/Source/Patch.pm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/Dpkg/Source/Patch.pm b/scripts/Dpkg/Source/Patch.pm index 57468fc4e..e9d59a3e9 100644 --- a/scripts/Dpkg/Source/Patch.pm +++ b/scripts/Dpkg/Source/Patch.pm @@ -422,6 +422,9 @@ sub analyze { my @patchorder; my $patch_header = ''; my $diff_count = 0; + my @patchprefix = ( '^--- ', '^\+\+\+ ', '^@@ -' ); + my $prefixindex = 0; + my $offset; my $line = _getline($self); @@ -433,11 +436,22 @@ sub analyze { # look for an Index: pseudo-header in the comments, because we would # not use it anyway, as we require both ---/+++ filename headers. while (1) { - if ($line =~ /^(?:--- |\+\+\+ |@@ -)/) { + if ($line =~ $patchprefix[$prefixindex]) { + $prefixindex++; + } else { + $prefixindex = 0; + } + if ($prefixindex == 3) { + $prefixindex = 0; + seek($self, $offset, 0); + $line = _getline($self); last; } else { $patch_header .= "$line\n"; } + if ($prefixindex == 0) { + $offset = tell($self); + } $line = _getline($self); last HUNK if not defined $line; } -- 2.39.5

