GNU bug report logs - #23763
Bug report: Grep stops, if a text file contains a null character after 32768 bytes

Previous Next

Package: grep;

Reported by: Bjoern Voigt <bjoernv <at> arcor.de>

Date: Mon, 13 Jun 2016 19:55:02 UTC

Severity: normal

Tags: notabug

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

Full log


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

From: Eric Blake <eblake <at> redhat.com>
To: Bjoern Voigt <bjoernv <at> arcor.de>, 23763-done <at> debbugs.gnu.org
Subject: Re: bug#23763: Bug report: Grep stops, if a text file contains a null
 character after 32768 bytes
Date: Mon, 13 Jun 2016 14:01:28 -0600
[Message part 1 (text/plain, inline)]
tag 23763 notabug
thanks

On 06/13/2016 01:45 PM, Bjoern Voigt wrote:
> Grep shows a bug, if it processes a text file with at least one embedded
> 0 (ASCII zero) character after byte 32768.

Thanks for the report.  However, this is not a bug in grep, but
documented behavior.  By definition, a text file CANNOT contain NUL
bytes; any file with NUL characters is a binary file.  You can still
make grep process it as a text file, but only with the '-a' flag.

> Grep stops with the error
> message "Binary file testfile.txt matches" and exit code 0. The error
> message is written to standard output. Any line after the 0 character is
> silently ignored in output.

POSIX allows this behavior, in that it says that grep's behavior is
undefined on non-text files (which you have by virtue of your NUL byte).

Since this is documented behavior of GNU grep when -a is not used, I'm
closing this as not a bug. But feel free to add further comments to this
thread.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 9 years and 55 days ago.

Previous Next


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