• Bug#1099170: dpkg-source: Source/Patch: fix parsing of patch header

    From Tj@21:1/5 to All on Sat Mar 1 08:50:01 2025
    XPost: linux.debian.bugs.dist

    This is a multi-part MIME message sent by reportbug.


    Package: dpkg-dev
    Version: 1.21.22
    Severity: normal
    File: /usr/bin/dpkg-source
    Tags: patch
    X-Debbugs-Cc: tj.iam.tj@proton.me

    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?= <marek.olsak@amd.com>
    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 <yuq825@gmail.com>
    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 <tj.iam.tj@proton.me>
    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?= <marek.olsak@amd.com>
    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 <yuq825@gmail.com>
    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 <tj.iam.tj@proton.me>
    ---
    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;
  • From Tj@1:229/2 to All on Sun Mar 2 10:00:01 2025
    XPost: linux.debian.bugs.dist
    From: tj.iam.tj@proton.me

    Package: dpkg-dev
    Followup-For: Bug #1099170
    X-Debbugs-Cc: tj.iam.tj@proton.me

    Revised patch that fixes an issue where $patchheader incorrectly
    included the hunk preamble.

    --- SoupGate-Win32 v1.05
    * Origin: you cannot sedate... all the things you hate (1:229/2)
  • From Tj@1:229/2 to All on Sun Mar 2 10:10:01 2025
    XPost: linux.debian.bugs.dist
    From: tj.iam.tj@proton.me

    This is a multi-part MIME message sent by reportbug.


    Package: dpkg-dev
    Followup-For: Bug #1099170
    X-Debbugs-Cc: tj.iam.tj@proton.me

    The (forgotten) revised patch!

    From 5518f0e15f2a94390081bdc7da31f535cc596147 Mon Sep 17 00:00:00 2001
    From: Tj <tj.iam.tj@proton.me>
    Date: Sun, 2 Mar 2025 08:49:21 +0000
    Subject: [PATCH 1/2] 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?= <marek.olsak@amd.com>
    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 <yuq825@gmail.com>
    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 <tj.iam.tj@proton.me>
    ---
    scripts/Dpkg/Source/Patch.pm | 18 ++++++++++++++++--
    1 file changed, 16 insertions(+), 2 deletions(-)

    diff --git a/scripts/Dpkg/Source/Patch.pm b/scripts/Dpkg/Source/Patch.pm
    index 57468fc4e..124b88a94 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 =~ /^(?:--- |\+\+\+ |@@ -)/) {
    - last;
    + if ($line =~ $patchprefix[$prefixindex]) {
    + $prefixindex++;
    } else {
    + $prefixindex = 0;
    + }
    + if ($prefixindex == 3) {
    + $prefixindex = 0;
    + seek($self, $offset, 0);
    + $line = _getline($self)
  • From Tj@1:229/2 to All on Sun Mar 2 10:40:02 2025
    XPost: linux.debian.bugs.dist
    From: tj.iam.tj@proton.me

    This is a multi-part MIME message sent by reportbug.


    Package: dpkg-dev
    Followup-For: Bug #1099170
    X-Debbugs-Cc: tj.iam.tj@proton.me

    Apologies that the previous attached patch did NOT include the changes I described. This one definitely does include dealing with partial hunk
    preambles correctly.

    From e00ca8faafc3fbbbc125be94cdfc31a3b1cc5243 Mon Sep 17 00:00:00 2001
    From: Tj <tj.iam.tj@proton.me>
    Date: Sun, 2 Mar 2025 09:19:40 +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?= <marek.olsak@amd.com>
    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 <yuq825@gmail.com>
    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 <tj.iam.tj@proton.me>
    ---
    scripts/Dpkg/Source/Patch.pm | 22 ++++++++++++++++++++--
    1 file changed, 20 insertions(+), 2 deletions(-)

    diff --git a/scripts/Dpkg/Source/Patch.pm b/scripts/Dpkg/Source/Patch.pm
    index 57468fc4e..16a486589 100644
    --- a/scripts/Dpkg/Source/Patch.pm
    +++ b/scripts/Dpkg/Source/Patch.pm
    @@ -422,6 +422,10 @@ sub analyze {
    my @patchorder;
    my $patch_header = '';
    my $diff_count = 0;
    + my @patchprefix = ( '^--- ', '^\+\+\+ ', '^@@ -' );
    + my $prefixindex = 0;
    + my $offset;
    + my $preamble = '';

    my $line = _getline($self);

    @@ -433,11 +437,25 @@ 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 =~ /^(?:--- |\+\+\+ |@@ -)/) {
    - last;
    + if ($line =~ $patchprefix[$prefixindex]) {
    + $prefixindex++;
    + $preamble .= "$line\n";
    } else {
    + $prefixindex = 0;
    + $patch_header .= "$preamble";
    + $preamble = '';
    +
  • From Guillem Jover@1:229/2 to All on Mon Mar 10 04:20:01 2025
    XPost: linux.debian.bugs.dist
    From: guillem@debian.org

    Control: reopen -1

    Hi!

    On Sun, 2025-03-02 at 09:33:20 +0000, Tj wrote:
    Package: dpkg-dev
    Followup-For: Bug #1099170
    X-Debbugs-Cc: tj.iam.tj@proton.me

    Apologies that the previous attached patch did NOT include the changes I described. This one definitely does include dealing with partial hunk preambles correctly.

    Ah, right (thanks for the private reply with the reasoning, although
    in general it would be better to send those to the bug directly! :), I
    see I was probably too quick to put this and the bug I referred in the
    same category, but they are indeed slightly different.

    I'm reopening for now to avoid it being archived, but I've still got
    some concerns that are similar to the ones affecting the other related
    bug, so in the end I think both might end up being unfixable for now.

    I'll ponder about this a bit, then give a reasoned reply later on.

    Thanks,
    Guillem

    --- SoupGate-Win32 v1.05
    * Origin: you cannot sedate... all the things you hate (1:229/2)