Bug#844770: xzcmp: SIGPIPE is raised because CMP does exit while the XZ commands are still writing to the pipe
control: tags -1 patch On 2018-12-17 13:24:50 [+0100], Étienne Mollier wrote: > I will keep the modification in my /usr/bin/xzcmp for some time, > in case it inadvertently breaks things. made a patch. > Cheers Sebastian From: Sebastian Andrzej Siewior Date: Thu, 24 Dec 2020 20:56:15 +0100 Subject: [PATCH] xzdiff: Trap SIGPIPE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `cmp' command will return early if a difference is found while the shell script is still invoking the decompressor which writes into the closed FD. This results in SIGPIPE / exit code 141. By ignoring SIGPIPE the real return code from `cmp' is observed which is `1' and xzdiff exits with `1'. Without ignoring SIGPIPE the exitcode 141 is observed and xzdiff returns with `2'. Reported to Debian BTS as #844770. Change suggested by Étienne Mollierö. BTS: https://bugs.debian.org/844770 Signed-off-by: Sebastian Andrzej Siewior --- src/scripts/xzdiff.in | 1 + 1 file changed, 1 insertion(+) diff --git a/src/scripts/xzdiff.in b/src/scripts/xzdiff.in index eb7825c1dfba9..d343a889e0e52 100644 --- a/src/scripts/xzdiff.in +++ b/src/scripts/xzdiff.in @@ -1,4 +1,5 @@ #!@POSIX_SHELL@ +trap '' PIPE # Copyright (C) 1998, 2002, 2006, 2007 Free Software Foundation # Copyright (C) 1993 Jean-loup Gailly -- 2.29.2
Bug#844770: xzcmp: SIGPIPE is raised because CMP does exit while the XZ commands are still writing to the pipe
On Tue, 12 Sep 2017 21:24:04 +0200 Sebastian Andrzej Siewior wrote: > On 2016-11-18 22:51:29 [+0100], ViaThinkSoft wrote: > > Version: 5.1.1alpha+20120614-2+b3 > > I noticed that xzcmp returns status code 2 (error) for a few file pairs, > > especially if they differ in size. > > can you please check if current 5.2.2 is affected and if so provide a > testcase? > Hello, Out of curiosity, I tried to reproduce the issue with xz-utils 5.2.2, and it seems it's still there. Here is a reproducer, using the change log of xz-utils, but any big text file, like system logs, seems to fit well that purpose: #! /bin/sh # Reproducer for bug #844770 xzcmp --version # Building test suite gunzip /usr/share/doc/xz-utils/changelog.gz -c > reproducer1 head -n50 reproducer1 > reproducer2 xz reproducer1 reproducer2 # Testing xzcmp reproducer1.xz reproducer2.xz faulty_exitcode="$?" printf 'here xzcmp sent exit code %s\n' "$faulty_exitcode" Execution of this script produces the following output: xzcmp (XZ Utils) 5.2.2 cmp: EOF on - after byte 1918, line 50 here xzcmp sent exit code 2 Also, a quick test appending the `trap '' PIPE` on top of the script /usr/bin/xzcmp did seem to do the job, per initial bug description message. xzcmp (XZ Utils) 5.2.2 cmp: EOF on - after byte 1918, line 50 here xzcmp sent exit code 1 I will keep the modification in my /usr/bin/xzcmp for some time, in case it inadvertently breaks things. Please tell me if I should attach the current changelog.gz, should the problem fail to reappear on your side. Cheers -- Étienne Mollier
Bug#844770: xzcmp: SIGPIPE is raised because CMP does exit while the XZ commands are still writing to the pipe
On 2016-11-18 22:51:29 [+0100], ViaThinkSoft wrote: > Version: 5.1.1alpha+20120614-2+b3 > I noticed that xzcmp returns status code 2 (error) for a few file pairs, > especially if they differ in size. can you please check if current 5.2.2 is affected and if so provide a testcase? Sebastian
Bug#844770: xzcmp: SIGPIPE is raised because CMP does exit while the XZ commands are still writing to the pipe
Package: xz-utils Version: 5.1.1alpha+20120614-2+b3 Severity: important Tags: newcomer I noticed that xzcmp returns status code 2 (error) for a few file pairs, especially if they differ in size. After some investigation, I found out that exit status 141 (SIGPIPE) is raised by the xz-commands, because cmp seems to have already quit after it found the first difference between the two streams. After that, the two xz commands write into the broken pipe. The exit status of the two xz commands is written into $xz_status . At the end of the script, if $xz_status is not 0, then xzcmp's exit status will become 2 (although the actual CMP did work fine in this specific case) Workaround: If the following line is added, the signal SIGPIPE (exit status 141) will not be raised by the xz commands, and thus, the xzdiff process will return the correct exit code: trap '' PIPE -- System Information: Debian Release: 8.6 APT prefers stable-updates APT policy: (500, 'stable-updates'), (500, 'stable') Architecture: amd64 (x86_64) Kernel: Linux 3.16.0-4-amd64 (SMP w/8 CPU cores) Locale: LANG=de_DE, LC_CTYPE=de_DE (charmap=ISO-8859-1) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) Versions of packages xz-utils depends on: ii libc6 2.19-18+deb8u6 ii liblzma5 5.1.1alpha+20120614-2+b3 xz-utils recommends no packages. xz-utils suggests no packages. -- no debconf information