Bug#652970: /usr/bin/dpkg-buildpackage: breaks quilt (3.0) packages with fuzzy patches

December 22nd, 2011 - 06:30 am ET by Michal Suchanek | Report spam
Package: dpkg-dev
Version: 1.16.1.2
Severity: normal
File: /usr/bin/dpkg-buildpackage


Building a quilt (3.0) package with fuzzy patch fails although quilt
aplies and unapplies the patch just fine. Worse, the package source may
be broken by dpk-buildpackage. It looks like the patch is applied but not
recorded as applied by quilt in the end.

$ quilt import ../qemu-kvm-0.14.1+dfsg/debian/patches/nops2.patch
Importing patch ../qemu-kvm-0.14.1+dfsg/debian/patches/nops2.patch (stored as debian/patches/nops2.patch)
$ quilt push -a
Applying patch debian/patches/nops2.patch
patching file hw/isa.h
Hunk #1 succeeded at 36 (offset 1 line).
patching file hw/pckbd.c
patching file vl.c
Hunk #1 succeeded at 2327 with fuzz 2 (offset 148 lines).
patching file qemu-options.hx
Hunk #1 succeeded at 2451 (offset 85 lines).

Now at patch debian/patches/nops2.patch
$ quilt pop -a
Removing patch debian/patches/nops2.patch
Restoring hw/isa.h
Restoring hw/pckbd.c
Restoring qemu-options.hx
Restoring vl.c

Removing patch debian/patches/scsi-disk-lazily-allocate-bounce-buffer-7285477ab1-CVE-2011-3346.diff
Restoring hw/scsi-disk.c

Removing patch debian/patches/scsi-disk-commonize-iovec-creation-between-reads-and-writes-103b40f51e-CVE-2011-3346.diff
Restoring hw/scsi-disk.c

Removing patch debian/patches/build-move-QEMU_INCLUDES-before-QEMU_CFLAGS-76dc3cf82c.diff
Restoring rules.mak

Removing patch debian/patches/05_report_debian_package_version.patch
Restoring configure

Removing patch debian/patches/04_use_etc_kvm_kvm-ifup.patch
Restoring net.h
Restoring net/tap.h

Removing patch debian/patches/03_use_etc_kvm_not_etc_qemu.patch
Restoring configure

Removing patch debian/patches/02_use_usr_share_kvm_fixed.patch
Restoring os-posix.c

No patches applied
$ quilt push -a
Applying patch debian/patches/02_use_usr_share_kvm_fixed.patch
patching file os-posix.c

Applying patch debian/patches/03_use_etc_kvm_not_etc_qemu.patch
patching file configure

Applying patch debian/patches/04_use_etc_kvm_kvm-ifup.patch
patching file net.h
patching file net/tap.h

Applying patch debian/patches/05_report_debian_package_version.patch
patching file configure

Applying patch debian/patches/build-move-QEMU_INCLUDES-before-QEMU_CFLAGS-76dc3cf82c.diff
patching file rules.mak

Applying patch debian/patches/scsi-disk-commonize-iovec-creation-between-reads-and-writes-103b40f51e-CVE-2011-3346.diff
patching file hw/scsi-disk.c

Applying patch debian/patches/scsi-disk-lazily-allocate-bounce-buffer-7285477ab1-CVE-2011-3346.diff
patching file hw/scsi-disk.c

Applying patch debian/patches/nops2.patch
patching file hw/isa.h
Hunk #1 succeeded at 36 (offset 1 line).
patching file hw/pckbd.c
patching file vl.c
Hunk #1 succeeded at 2327 with fuzz 2 (offset 148 lines).
patching file qemu-options.hx
Hunk #1 succeeded at 2451 (offset 85 lines).

Now at patch debian/patches/nops2.patch
$ dpkg-buildpackage -j6
dpkg-buildpackage: source package qemu-kvm
dpkg-buildpackage: source version 0.15.1+dfsg-1nopsaux1
dpkg-buildpackage: source changed by Michal Suchanek <hramrach@centrum.cz>
dpkg-buildpackage: host architecture amd64
dpkg-source --before-build qemu-kvm-0.15.1+dfsg
fakeroot debian/rules clean
dh_testdir
rm -rf build/
# clean up upstream leftovers
rm -f scripts/*.pyc
dh_clean
dpkg-source -b qemu-kvm-0.15.1+dfsg
dpkg-source: info: using source format `3.0 (quilt)'
dpkg-source: info: building qemu-kvm using existing ./qemu-kvm_0.15.1+dfsg.orig.tar.gz
patching file hw/isa.h
Hunk #1 succeeded at 36 (offset 1 line).
patching file hw/pckbd.c
patching file vl.c
Hunk #1 FAILED at 2179.
1 out of 1 hunk FAILED -- saving rejects to file vl.c.rej
patching file qemu-options.hx
Hunk #1 succeeded at 2451 (offset 85 lines).
dpkg-source: error: LC_ALL=C patch -t -F 0 -N -p1 -u -V never -g0 -E -b -B .pc/nops2.patch/ < qemu-kvm-0.15.1+dfsg.orig.2OmAtg/debian/patches/nops2.patch gav
e error exit status 1
dpkg-buildpackage: error: dpkg-source -b qemu-kvm-0.15.1+dfsg gave error exit status 2
$ quilt pop -a
Removing patch debian/patches/nops2.patch
Restoring hw/isa.h
Restoring hw/pckbd.c
Restoring qemu-options.hx
Restoring vl.c

Removing patch debian/patches/scsi-disk-lazily-allocate-bounce-buffer-7285477ab1-CVE-2011-3346.diff
Restoring hw/scsi-disk.c

Removing patch debian/patches/scsi-disk-commonize-iovec-creation-between-reads-and-writes-103b40f51e-CVE-2011-3346.diff
Restoring hw/scsi-disk.c

Removing patch debian/patches/build-move-QEMU_INCLUDES-before-QEMU_CFLAGS-76dc3cf82c.diff
Restoring rules.mak

Removing patch debian/patches/05_report_debian_package_version.patch
Restoring configure

Removing patch debian/patches/04_use_etc_kvm_kvm-ifup.patch
Restoring net.h
Restoring net/tap.h

Removing patch debian/patches/03_use_etc_kvm_not_etc_qemu.patch
Restoring configure

Removing patch debian/patches/02_use_usr_share_kvm_fixed.patch
Restoring os-posix.c

No patches applied
$ dpkg-buildpackage -j6
dpkg-buildpackage: source package qemu-kvm
dpkg-buildpackage: source version 0.15.1+dfsg-1nopsaux1
dpkg-buildpackage: source changed by Michal Suchanek <hramrach@centrum.cz>
dpkg-buildpackage: host architecture amd64
dpkg-source --before-build qemu-kvm-0.15.1+dfsg
dpkg-source: info: patches are not applied, applying them now
dpkg-source: info: applying 02_use_usr_share_kvm_fixed.patch
dpkg-source: info: applying 03_use_etc_kvm_not_etc_qemu.patch
dpkg-source: info: applying 04_use_etc_kvm_kvm-ifup.patch
dpkg-source: info: applying 05_report_debian_package_version.patch
dpkg-source: info: applying build-move-QEMU_INCLUDES-before-QEMU_CFLAGS-76dc3cf82c.diff
dpkg-source: info: applying scsi-disk-commonize-iovec-creation-between-reads-and-writes-103b40f51e-CVE-2011-3346.diff
dpkg-source: info: applying scsi-disk-lazily-allocate-bounce-buffer-7285477ab1-CVE-2011-3346.diff
dpkg-source: info: applying nops2.patch
patching file hw/isa.h
Hunk #1 succeeded at 36 (offset 1 line).
patching file hw/pckbd.c
patching file vl.c
Hunk #1 FAILED at 2179.
1 out of 1 hunk FAILED -- saving rejects to file vl.c.rej
patching file qemu-options.hx
Hunk #1 succeeded at 2451 (offset 85 lines).
dpkg-source: error: LC_ALL=C patch -t -F 0 -N -p1 -u -V never -g0 -E -b -B .pc/nops2.patch/ < qemu-kvm-0.15.1+dfsg/debian/patches/nops2.patch gave error exit
status 1
dpkg-buildpackage: error: dpkg-source --before-build qemu-kvm-0.15.1+dfsg gave error exit status 1
$ quilt push -a
Applying patch debian/patches/nops2.patch
patching file hw/isa.h
Hunk #1 FAILED at 35.
1 out of 1 hunk FAILED -- rejects in file hw/isa.h
patching file hw/pckbd.c
Hunk #1 succeeded at 128 with fuzz 2 (offset 2 lines).
Hunk #2 FAILED at 171.
Hunk #3 FAILED at 207.
Hunk #4 FAILED at 313.
Hunk #5 FAILED at 344.
Hunk #6 FAILED at 422.
Hunk #7 FAILED at 431.
Hunk #8 FAILED at 471.
Hunk #9 FAILED at 481.
8 out of 9 hunks FAILED -- rejects in file hw/pckbd.c
patching file vl.c
Hunk #1 succeeded at 2327 with fuzz 2 (offset 148 lines).
patching file qemu-options.hx
Hunk #1 succeeded at 2462 with fuzz 2 (offset 96 lines).
Patch debian/patches/nops2.patch does not apply (enforce with -f)
$ quilt pop -a
Removing patch debian/patches/scsi-disk-lazily-allocate-bounce-buffer-7285477ab1-CVE-2011-3346.diff
Restoring hw/scsi-disk.c

Removing patch debian/patches/scsi-disk-commonize-iovec-creation-between-reads-and-writes-103b40f51e-CVE-2011-3346.diff
Restoring hw/scsi-disk.c

Removing patch debian/patches/build-move-QEMU_INCLUDES-before-QEMU_CFLAGS-76dc3cf82c.diff
Restoring rules.mak

Removing patch debian/patches/05_report_debian_package_version.patch
Restoring configure

Removing patch debian/patches/04_use_etc_kvm_kvm-ifup.patch
Restoring net.h
Restoring net/tap.h

Removing patch debian/patches/03_use_etc_kvm_not_etc_qemu.patch
Restoring configure

Removing patch debian/patches/02_use_usr_share_kvm_fixed.patch
Restoring os-posix.c

No patches applied
$ quilt push -a
Applying patch debian/patches/02_use_usr_share_kvm_fixed.patch
patching file os-posix.c

Applying patch debian/patches/03_use_etc_kvm_not_etc_qemu.patch
patching file configure

Applying patch debian/patches/04_use_etc_kvm_kvm-ifup.patch
patching file net.h
patching file net/tap.h

Applying patch debian/patches/05_report_debian_package_version.patch
patching file configure

Applying patch debian/patches/build-move-QEMU_INCLUDES-before-QEMU_CFLAGS-76dc3cf82c.diff
patching file rules.mak

Applying patch debian/patches/scsi-disk-commonize-iovec-creation-between-reads-and-writes-103b40f51e-CVE-2011-3346.diff
patching file hw/scsi-disk.c

Applying patch debian/patches/scsi-disk-lazily-allocate-bounce-buffer-7285477ab1-CVE-2011-3346.diff
patching file hw/scsi-disk.c

Applying patch debian/patches/nops2.patch
patching file hw/isa.h
Hunk #1 FAILED at 35.
1 out of 1 hunk FAILED -- rejects in file hw/isa.h
patching file hw/pckbd.c
Hunk #1 succeeded at 128 with fuzz 2 (offset 2 lines).
Hunk #2 FAILED at 171.
Hunk #3 FAILED at 207.
Hunk #4 FAILED at 313.
Hunk #5 FAILED at 344.
Hunk #6 FAILED at 422.
Hunk #7 FAILED at 431.
Hunk #8 FAILED at 471.
Hunk #9 FAILED at 481.
8 out of 9 hunks FAILED -- rejects in file hw/pckbd.c
patching file vl.c
Hunk #1 succeeded at 2327 with fuzz 2 (offset 148 lines).
patching file qemu-options.hx
Hunk #1 succeeded at 2462 with fuzz 2 (offset 96 lines).
Patch debian/patches/nops2.patch does not apply (enforce with -f)



Debian Release: wheezy/sid
APT prefers stable
APT policy: (900, 'stable'), (500, 'testing'), (410, 'unstable'), (200, 'experimental'), (111, 'oldstable'), (107, 'natty-updates'), (107, 'natty')
Architecture: amd64 (x86_64)

Kernel: Linux 3.2.0-rc3 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) (ignored: LC_ALL set to en_US.UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages dpkg-dev depends on:
ii base-files 6.5 Debian base system miscellaneous f
ii binutils 2.22-2 GNU assembler, linker and binary u
ii bzip2 1.0.5-6 high-quality block-sorting file co
ii libdpkg-perl 1.16.1.2 Dpkg perl modules
ii make 3.81-8.1 An utility for Directing compilati
ii patch 2.6-2 Apply a diff file to an original
ii xz-utils 5.0.0-2 XZ-format compression utilities

Versions of packages dpkg-dev recommends:
ii bcc [c-compiler] 0.16.17-3.1 16-bit x86 C compiler
ii build-essential 11.5 Informational list of build-essent
ii fakeroot 1.14.4-1 Gives a fake root environment
ii gcc [c-compiler] 4:4.6.1-3 GNU C compiler
ii gcc-4.4 [c-compiler] 4.4.6-14 GNU C compiler
ii gcc-4.5 [c-compiler] 4.5.3-9 The GNU C compiler
ii gcc-4.6 [c-compiler] 4.6.2-7 GNU C compiler
ii gnupg 1.4.10-4 GNU privacy guard - a free PGP rep
ii gpgv 1.4.10-4 GNU privacy guard - signature veri
ii libalgorithm-merge-perl 0.08-2 Perl module for three-way merge of

Versions of packages dpkg-dev suggests:
ii debian-keyring 2010.12.29 GnuPG keys of Debian Developers




To UNSUBSCRIBE, email to debian-bugs-dist-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
email Follow the discussionReplies 2 repliesReplies Make a reply

Replies

#1 Raphael Hertzog
December 22nd, 2011 - 10:20 am ET | Report spam
On Thu, 22 Dec 2011, Michal Suchanek wrote:
Building a quilt (3.0) package with fuzzy patch fails although quilt
aplies and unapplies the patch just fine.



This is normal and not really a bug. We really want patches that apply
without fuzz. Otherwise there are too many risks of misapplied patches.

Worse, the package source may be broken by dpkg-buildpackage. It looks
like the patch is applied but not recorded as applied by quilt in the
end.



This is worthy of investigation. But I don't really

[ All patches applied ]
$ dpkg-buildpackage -j6


[...]
dpkg-source -b qemu-kvm-0.15.1+dfsg
dpkg-source: info: using source format `3.0 (quilt)'
dpkg-source: info: building qemu-kvm using existing ./qemu-kvm_0.15.1+dfsg.orig.tar.gz
patching file hw/isa.h
Hunk #1 succeeded at 36 (offset 1 line).
patching file hw/pckbd.c
patching file vl.c
Hunk #1 FAILED at 2179.
1 out of 1 hunk FAILED -- saving rejects to file vl.c.rej
patching file qemu-options.hx
Hunk #1 succeeded at 2451 (offset 85 lines).
dpkg-source: error: LC_ALL=C patch -t -F 0 -N -p1 -u -V never -g0 -E -b -B .pc/nops2.patch/ < qemu-kvm-0.15.1+dfsg.orig.2OmAtg/debian/patches/nops2.patch gav
e error exit status 1
dpkg-buildpackage: error: dpkg-source -b qemu-kvm-0.15.1+dfsg gave error exit status 2



Since all patches were already applied, the failure happens when
dpkg-source tries to apply patches to the pristine copy unpacked in a
temporary directory. So it can't really mess up with your source package.

So it's to be expected that "quilt pop -a" works as usual:
$ quilt pop -a
Removing patch debian/patches/nops2.patch


[...]
No patches applied



But now if you run it with patches unapplied, dpkg-source --before-build
will try to apply them:
$ dpkg-buildpackage -j6


[...]
dpkg-source --before-build qemu-kvm-0.15.1+dfsg
dpkg-source: info: patches are not applied, applying them now
dpkg-source: info: applying 02_use_usr_share_kvm_fixed.patch
dpkg-source: info: applying 03_use_etc_kvm_not_etc_qemu.patch
dpkg-source: info: applying 04_use_etc_kvm_kvm-ifup.patch
dpkg-source: info: applying 05_report_debian_package_version.patch
dpkg-source: info: applying build-move-QEMU_INCLUDES-before-QEMU_CFLAGS-76dc3cf82c.diff
dpkg-source: info: applying scsi-disk-commonize-iovec-creation-between-reads-and-writes-103b40f51e-CVE-2011-3346.diff
dpkg-source: info: applying scsi-disk-lazily-allocate-bounce-buffer-7285477ab1-CVE-2011-3346.diff
dpkg-source: info: applying nops2.patch
patching file hw/isa.h
Hunk #1 succeeded at 36 (offset 1 line).
patching file hw/pckbd.c
patching file vl.c
Hunk #1 FAILED at 2179.
1 out of 1 hunk FAILED -- saving rejects to file vl.c.rej
patching file qemu-options.hx
Hunk #1 succeeded at 2451 (offset 85 lines).
dpkg-source: error: LC_ALL=C patch -t -F 0 -N -p1 -u -V never -g0 -E -b -B .pc/nops2.patch/ < qemu-kvm-0.15.1+dfsg/debian/patches/nops2.patch gave error exit
status 1
dpkg-buildpackage: error: dpkg-source --before-build qemu-kvm-0.15.1+dfsg gave error exit status 1



So apparently at this point, despite the failure, patch modified several
files and will not undo those changes. The correct thing to do would then
be to restore the files from .pc/nops2.patch/ so that we're back to the
initial state before we tried to apply this patch (and then clean up that
directory too).

FWIW that's what quilt is doing (with the help of its backup-files
script).

Another approach could be to --dry-run the patch first but that would be
too expensive and would impact everybody.

Yet another idea would be to re-apply the patch with the -R option. It
would drop the changes already applied (and fail again due to the changes
that failed to apply). This is probably easier to implement than the
restore from .pc/nops2.patch/ but not very clean.

Cheers,
Raphaël Hertzog ◈ Debian Developer

Pre-order a copy of the Debian Administrator's Handbook and help
liberate it: http://debian-handbook.info/liberation/



To UNSUBSCRIBE, email to
with a subject of "unsubscribe". Trouble? Contact

Similar topics