GNU bug report logs - #76452
3.11 critical bug: diff -Naur a b does not show a unified diff when one of the file is empty

Previous Next

Package: diffutils;

Reported by: Kate Deplaix <kit-ty-kate <at> outlook.com>

Date: Fri, 21 Feb 2025 04:48:04 UTC

Severity: normal

Merged with 76453, 76454

Found in version 3.11

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 76452 in the body.
You can then email your comments to 76452 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-diffutils <at> gnu.org:
bug#76452; Package diffutils. (Fri, 21 Feb 2025 04:48:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Kate Deplaix <kit-ty-kate <at> outlook.com>:
New bug report received and forwarded. Copy sent to bug-diffutils <at> gnu.org. (Fri, 21 Feb 2025 04:48:05 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Kate Deplaix <kit-ty-kate <at> outlook.com>
To: "bug-diffutils <at> gnu.org" <bug-diffutils <at> gnu.org>
Subject: 3.11 critical bug: diff -Naur a b does not show a unified diff when
 one of the file is empty
Date: Thu, 20 Feb 2025 15:25:05 +0000
[Message part 1 (text/plain, inline)]
Hi,

While using diffutils 3.11 instead of 3.10, i've noticed a critical bug in diff reproducible with the following setup:

$ cd /tmp
$ mkdir a b
$ touch a/test
$ echo content > b/test

With diffutils 3.10, "diff -Naur a b" returns:

diff -Naur a/test b/test
--- a/test   2025-02-20 14:50:07.870258052 +0000
+++ b/test   2025-02-20 14:50:18.957287641 +0000
@@ -0,0 +1 @@
+content

but with diffutils 3.11, the same command returns:

File a/test is a regular empty file while file b/test is a regular file

Given no mention of this change appear in the changelog, i'm guessing this is an unintended change. In my opinion this bug is critical and the 3.11 release should be marked as broken to avoid more distributions using it.

Warm regards,
Kate Deplaix
[Message part 2 (text/html, inline)]

Information forwarded to bug-diffutils <at> gnu.org:
bug#76452; Package diffutils. (Fri, 21 Feb 2025 06:11:02 GMT) Full text and rfc822 format available.

Message #8 received at 76452 <at> debbugs.gnu.org (full text, mbox):

From: Collin Funk <collin.funk1 <at> gmail.com>
To: Kate Deplaix <kit-ty-kate <at> outlook.com>, Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 76452 <at> debbugs.gnu.org
Subject: Re: [bug-diffutils] bug#76452: 3.11 critical bug: diff -Naur a b
 does not show a unified diff when one of the file is empty
Date: Thu, 20 Feb 2025 22:10:44 -0800
[Message part 1 (text/plain, inline)]
Hi Katie,

Kate Deplaix <kit-ty-kate <at> outlook.com> writes:

> With diffutils 3.10, "diff -Naur a b" returns:
>
> diff -Naur a/test b/test
> --- a/test   2025-02-20 14:50:07.870258052 +0000
> +++ b/test   2025-02-20 14:50:18.957287641 +0000
> @@ -0,0 +1 @@
> +content
>
> but with diffutils 3.11, the same command returns:
>
> File a/test is a regular empty file while file b/test is a regular file

Good catch.

CC'ing Paul Eggert since I think that I found the cause and it appears
unintentional to me.

Commit e016d12581ac4ea6be1ded88279527ceface74e1 has the following
ChangeLog:

    diff: improve symlink handling, avoiding a race
    [...]
    (compare_prepped_files): Use filetype and stat macros, not detype.
    [...]

Where filetype refers to a constant string returned by Gnulib's
c_file_type function. The relevant lines are here:

  if (S_ISREG (st->st_mode))
    return st->st_size == 0 ? N_("regular empty file") : N_("regular file");

So empty files will be treated as different file types because of that
change.

I have attached a patch to check for this condition.

Collin

[0001-diff-don-t-treat-empty-files-as-a-different-file-typ.patch (text/x-patch, attachment)]

Information forwarded to bug-diffutils <at> gnu.org:
bug#76452; Package diffutils. (Fri, 21 Feb 2025 06:40:04 GMT) Full text and rfc822 format available.

Message #11 received at 76452 <at> debbugs.gnu.org (full text, mbox):

From: Collin Funk <collin.funk1 <at> gmail.com>
To: Kate Deplaix <kit-ty-kate <at> outlook.com>
Cc: Paul Eggert <eggert <at> cs.ucla.edu>, 76452 <at> debbugs.gnu.org
Subject: Re: [bug-diffutils] bug#76452: bug#76452: 3.11 critical bug: diff
 -Naur a b does not show a unified diff when one of the file is empty
Date: Thu, 20 Feb 2025 22:39:40 -0800
[Message part 1 (text/plain, inline)]
Collin Funk <collin.funk1 <at> gmail.com> writes:

> I have attached a patch to check for this condition.

Since it seems easy to overlook this in the future I have attached a
patch with the test case as well.

Collin

[0001-diff-add-a-test-case-for-the-recent-empty-file-bug.patch (text/x-patch, attachment)]

Information forwarded to bug-diffutils <at> gnu.org:
bug#76452; Package diffutils. (Sat, 22 Feb 2025 06:12:03 GMT) Full text and rfc822 format available.

Message #14 received at 76452 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Collin Funk <collin.funk1 <at> gmail.com>,
 Kate Deplaix <kit-ty-kate <at> outlook.com>
Cc: 76452 <at> debbugs.gnu.org
Subject: Re: [bug-diffutils] bug#76452: bug#76452: 3.11 critical bug: diff
 -Naur a b does not show a unified diff when one of the file is empty
Date: Fri, 21 Feb 2025 23:11:51 -0700
On 2/20/25 23:39, Collin Funk wrote:
> Since it seems easy to overlook this in the future I have attached a
> patch with the test case as well.

Thanks, I installed that.




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Sat, 22 Feb 2025 06:12:03 GMT) Full text and rfc822 format available.

Notification sent to Kate Deplaix <kit-ty-kate <at> outlook.com>:
bug acknowledged by developer. (Sat, 22 Feb 2025 06:12:04 GMT) Full text and rfc822 format available.

Message #19 received at 76452-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Collin Funk <collin.funk1 <at> gmail.com>
Cc: 76452-done <at> debbugs.gnu.org, Kate Deplaix <kit-ty-kate <at> outlook.com>
Subject: Re: [bug-diffutils] bug#76452: 3.11 critical bug: diff -Naur a b does
 not show a unified diff when one of the file is empty
Date: Fri, 21 Feb 2025 23:11:22 -0700
[Message part 1 (text/plain, inline)]
Thanks for the diagnosis and the patch. I installed the attached 
instead, so as to decouple this part of the code from the part that 
turns file types into strings.
[0001-diff-don-t-treat-empty-files-as-a-different-file-typ.patch (text/x-patch, attachment)]
[0001-maint-mention-bug-76452-in-NEWS.patch (text/x-patch, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 22 Mar 2025 11:24:11 GMT) Full text and rfc822 format available.

bug unarchived. Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Mon, 24 Mar 2025 23:19:03 GMT) Full text and rfc822 format available.

Merged 76452 76453 76454. Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Mon, 24 Mar 2025 23:19:04 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 22 Apr 2025 11:24:13 GMT) Full text and rfc822 format available.

This bug report was last modified 17 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.