From unknown Sun Jun 15 08:41:30 2025 X-Loop: help-debbugs@gnu.org Subject: bug#33898: grep reports binary file matches even with -I option Resent-From: Britton Kerin Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Fri, 28 Dec 2018 22:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 33898 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: 33898@debbugs.gnu.org X-Debbugs-Original-To: bug-grep@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.15460370642494 (code B ref -1); Fri, 28 Dec 2018 22:45:01 +0000 Received: (at submit) by debbugs.gnu.org; 28 Dec 2018 22:44:24 +0000 Received: from localhost ([127.0.0.1]:40699 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gd0rg-0000eA-1P for submit@debbugs.gnu.org; Fri, 28 Dec 2018 17:44:24 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40610) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gd0rd-0000dw-O3 for submit@debbugs.gnu.org; Fri, 28 Dec 2018 17:44:22 -0500 Received: from lists.gnu.org ([208.118.235.17]:38377) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gd0rW-00022I-2L for submit@debbugs.gnu.org; Fri, 28 Dec 2018 17:44:14 -0500 Received: from eggs.gnu.org ([208.118.235.92]:54465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gd0rU-0006xk-H6 for bug-grep@gnu.org; Fri, 28 Dec 2018 17:44:13 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gd0ZV-0003VM-Du for bug-grep@gnu.org; Fri, 28 Dec 2018 17:25:39 -0500 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]:36016) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gd0ZV-0003Uz-1B for bug-grep@gnu.org; Fri, 28 Dec 2018 17:25:37 -0500 Received: by mail-lf1-x132.google.com with SMTP id a16so15350921lfg.3 for ; Fri, 28 Dec 2018 14:25:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=juhXYlJmO6RmBr4P5tbPzs8c2/5pY4I6Nvybm+2M5iY=; b=XJTmuQRv7l6nnPiIKiA7uhLy3TtuAG/yZnxfYwZcvqZhtzA26yiQdeIX9ycVwpK7Dp 1Yf4xts9SFRgCZfNzNsR/zLIaf6zWOI4nXSu+sW0AnwKFUolWxtzF8SsCjR7bBi2v7Ep 8Eb57/VfKS43mRAJ3OWw3ZtA3lHZ8GT8ahCPhLwa8/nPSiQYPLw99XExAWqX0BLs3SMn BNRazIbk4yE+S17le1XiGYanZRFE7Fw/OJL25oSEF2Op6IrmnUDP5w101SAqqo/CteD1 TaUimjgrd57lpfNV9Zad/6TVTL4/BwUqA9UQ0ptrIqMMPiEfqK6/yrsJdDLwZIgjEWIJ hAcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=juhXYlJmO6RmBr4P5tbPzs8c2/5pY4I6Nvybm+2M5iY=; b=DQdoMFzfaNhPDUJ5NDqDcqfCUW64myNi6ZjWUlT3YB0nV3y4YX11ZwXkx8cxpx26Qf ctrh3oDkWmnbNjz23NQ6Ce9vjZsH1/AviNR2pJkdKxj8gRzRMmqF6+RYMnUPzaBwwARt kYi0ejZfqA1GkffPfYbvZTxJ9AZHVbLv1tafdT3lA01Y9eGMIsl/T6lFVJF2W7Y4REYV VUv/7zevlpVQi+nqjnteZZNG+btAw7q2Tlrt7yItxjoZ/q5sFwr1aHfe99GOd/xq9MZH hlwgSUxeQ6sNww4VCjRIXW0gojhnPuQhc6qrIUNuCo0xnQblpSoIuXG/Opdkr4tH6hyi AUFQ== X-Gm-Message-State: AA+aEWYniPXDb2dCk0/29Vxf6kWkhvlCbiIXfl7nnioKWNfstv7O5SZ6 GjS9dgRVBHNNqxCRcqaw5DjhN2qJBAvaxlFN002bt9Z9K9c= X-Google-Smtp-Source: AFSGD/X2Mg+6ZQutLKevJAEcuEoUl0FJkKxn+Dgwe3dlM1RR6UPY/5yZ18m13iX3YdnsP6ZGMOh2fS6bV9kjOhDY4vs= X-Received: by 2002:a19:c345:: with SMTP id t66mr14137126lff.55.1546035935179; Fri, 28 Dec 2018 14:25:35 -0800 (PST) MIME-Version: 1.0 From: Britton Kerin Date: Fri, 28 Dec 2018 13:25:23 -0900 Message-ID: Content-Type: multipart/mixed; boundary="000000000000bb42be057e1c8a01" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::132 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Spam-Score: -4.0 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) --000000000000bb42be057e1c8a01 Content-Type: text/plain; charset="UTF-8" The man page description of the -I option implies that grep might output match information for a binary file if it hasn't "discovered" that the file is binary yet. It seems that even with -I Binary file matches may be reported, as this example on the attached file shows: $ 'grep' -I -e '.' bca9b83eeb33810a61cca0485f504f98540156 Binary file bca9b83eeb33810a61cca0485f504f98540156 matches This seems like a bug, because it's clearly produced at a point when grep has already decided the file is binary, and scripts can reasonably expect that any matches that do occur in a so-far-unknown-to-be-binary file will conform to the output format specified by other other options (e.g. -n) and feature an actual file name. Britton --000000000000bb42be057e1c8a01 Content-Type: application/octet-stream; name=bca9b83eeb33810a61cca0485f504f98540156 Content-Disposition: attachment; filename=bca9b83eeb33810a61cca0485f504f98540156 Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_jq8lexqw0 eAGlj0tOAzEQBVn7FH0BIv/anwhFEVuQWLBgGc3Y7cQKY49MR3B8BiFOwPLV4qkq9WWpDDrYOx5E oBFN1hiDV7kUZ0IKNmjjTZAl6jJjJB2dI7FOgxqD8ZSUp4DeZJtl9EpG5bGUSA4pzdb6mI1EMd34 0gc8jsrcGzxThycatcHD/It21595PC9Tfd+lvhxAocVNxWkJ9zJKKTa6yTL980bUlukLNgseU6LT Z+XLaR19/dj/9cBbH9fazvDK+eXG4hvxsVs+ --000000000000bb42be057e1c8a01-- From unknown Sun Jun 15 08:41:30 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Britton Kerin Subject: bug#33898: closed (grep reports binary file matches even with -I option) Message-ID: References: X-Gnu-PR-Message: they-closed 33898 X-Gnu-PR-Package: grep Reply-To: 33898@debbugs.gnu.org Date: Mon, 21 Jan 2019 03:45:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1548042302-22621-1" This is a multi-part message in MIME format... ------------=_1548042302-22621-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #33898: grep reports binary file matches even with -I option which was filed against the grep package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 33898@debbugs.gnu.org. --=20 33898: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D33898 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1548042302-22621-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 33898-done) by debbugs.gnu.org; 21 Jan 2019 03:44:05 +0000 Received: from localhost ([127.0.0.1]:39322 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1glQVJ-0005rQ-06 for submit@debbugs.gnu.org; Sun, 20 Jan 2019 22:44:05 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:57278) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1glQVG-0005qj-KV for 33898-done@debbugs.gnu.org; Sun, 20 Jan 2019 22:44:03 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 9538B160FDC; Sun, 20 Jan 2019 19:43:56 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id oH4MYgYkdQ8d; Sun, 20 Jan 2019 19:43:55 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id C622116100D; Sun, 20 Jan 2019 19:43:55 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 6PBpMPtpDh_o; Sun, 20 Jan 2019 19:43:55 -0800 (PST) Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 95D84160D13; Sun, 20 Jan 2019 19:43:55 -0800 (PST) To: Britton Kerin From: Paul Eggert Subject: grep reports binary file matches even with -I option Organization: UCLA Computer Science Department Message-ID: Date: Sun, 20 Jan 2019 19:43:55 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------9602E17CEBB95116947AFC33" Content-Language: en-US X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 33898-done Cc: 33898-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) This is a multi-part message in MIME format. --------------9602E17CEBB95116947AFC33 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thanks for reporting the problem. This is a bug in grep's man page, which wasn't updated back in 2016 when I updated the main documentation. (The man page is lower priority and is sometimes neglected.) I installed the attached patch to fix it. --------------9602E17CEBB95116947AFC33 Content-Type: text/x-patch; name="0001-doc-binary-files-update-in-man-page.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-doc-binary-files-update-in-man-page.patch" >From f3b521b87d178205811a22aff2974d77f1aa3054 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 20 Jan 2019 19:38:32 -0800 Subject: [PATCH] doc: --binary-files update in man page * doc/grep.in.1: Adjust --binary-files description to match that in doc/grep.texi. When I updated the documentation in 2016-09-09T01:33:14!eggert@cs.ucla.edu I forgot to update the man page accordingly (Bug#33898). --- doc/grep.in.1 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/grep.in.1 b/doc/grep.in.1 index 9d0d494..dd25589 100644 --- a/doc/grep.in.1 +++ b/doc/grep.in.1 @@ -505,11 +505,14 @@ By default, .I TYPE is .BR binary , -and when +and +.B grep +suppresses output after null input binary data is discovered, +and suppresses output lines that contain improperly encoded data. +When some output is suppressed, .B grep -discovers that a file is binary it suppresses any further output, and -instead outputs either a one-line message saying that a binary file -matches, or no message if there is no match. +follows any output +with a one-line message saying that a binary file matches. .IP If .I TYPE @@ -517,7 +520,7 @@ is .BR without\-match , when .B grep -discovers that a file is binary it assumes that the rest of the file +discovers null input binary data it assumes that the rest of the file does not match; this is equivalent to the .B \-I option. -- 2.17.1 --------------9602E17CEBB95116947AFC33-- ------------=_1548042302-22621-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 28 Dec 2018 22:44:24 +0000 Received: from localhost ([127.0.0.1]:40699 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gd0rg-0000eA-1P for submit@debbugs.gnu.org; Fri, 28 Dec 2018 17:44:24 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40610) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gd0rd-0000dw-O3 for submit@debbugs.gnu.org; Fri, 28 Dec 2018 17:44:22 -0500 Received: from lists.gnu.org ([208.118.235.17]:38377) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gd0rW-00022I-2L for submit@debbugs.gnu.org; Fri, 28 Dec 2018 17:44:14 -0500 Received: from eggs.gnu.org ([208.118.235.92]:54465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gd0rU-0006xk-H6 for bug-grep@gnu.org; Fri, 28 Dec 2018 17:44:13 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gd0ZV-0003VM-Du for bug-grep@gnu.org; Fri, 28 Dec 2018 17:25:39 -0500 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]:36016) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gd0ZV-0003Uz-1B for bug-grep@gnu.org; Fri, 28 Dec 2018 17:25:37 -0500 Received: by mail-lf1-x132.google.com with SMTP id a16so15350921lfg.3 for ; Fri, 28 Dec 2018 14:25:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=juhXYlJmO6RmBr4P5tbPzs8c2/5pY4I6Nvybm+2M5iY=; b=XJTmuQRv7l6nnPiIKiA7uhLy3TtuAG/yZnxfYwZcvqZhtzA26yiQdeIX9ycVwpK7Dp 1Yf4xts9SFRgCZfNzNsR/zLIaf6zWOI4nXSu+sW0AnwKFUolWxtzF8SsCjR7bBi2v7Ep 8Eb57/VfKS43mRAJ3OWw3ZtA3lHZ8GT8ahCPhLwa8/nPSiQYPLw99XExAWqX0BLs3SMn BNRazIbk4yE+S17le1XiGYanZRFE7Fw/OJL25oSEF2Op6IrmnUDP5w101SAqqo/CteD1 TaUimjgrd57lpfNV9Zad/6TVTL4/BwUqA9UQ0ptrIqMMPiEfqK6/yrsJdDLwZIgjEWIJ hAcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=juhXYlJmO6RmBr4P5tbPzs8c2/5pY4I6Nvybm+2M5iY=; b=DQdoMFzfaNhPDUJ5NDqDcqfCUW64myNi6ZjWUlT3YB0nV3y4YX11ZwXkx8cxpx26Qf ctrh3oDkWmnbNjz23NQ6Ce9vjZsH1/AviNR2pJkdKxj8gRzRMmqF6+RYMnUPzaBwwARt kYi0ejZfqA1GkffPfYbvZTxJ9AZHVbLv1tafdT3lA01Y9eGMIsl/T6lFVJF2W7Y4REYV VUv/7zevlpVQi+nqjnteZZNG+btAw7q2Tlrt7yItxjoZ/q5sFwr1aHfe99GOd/xq9MZH hlwgSUxeQ6sNww4VCjRIXW0gojhnPuQhc6qrIUNuCo0xnQblpSoIuXG/Opdkr4tH6hyi AUFQ== X-Gm-Message-State: AA+aEWYniPXDb2dCk0/29Vxf6kWkhvlCbiIXfl7nnioKWNfstv7O5SZ6 GjS9dgRVBHNNqxCRcqaw5DjhN2qJBAvaxlFN002bt9Z9K9c= X-Google-Smtp-Source: AFSGD/X2Mg+6ZQutLKevJAEcuEoUl0FJkKxn+Dgwe3dlM1RR6UPY/5yZ18m13iX3YdnsP6ZGMOh2fS6bV9kjOhDY4vs= X-Received: by 2002:a19:c345:: with SMTP id t66mr14137126lff.55.1546035935179; Fri, 28 Dec 2018 14:25:35 -0800 (PST) MIME-Version: 1.0 From: Britton Kerin Date: Fri, 28 Dec 2018 13:25:23 -0900 Message-ID: Subject: grep reports binary file matches even with -I option To: bug-grep@gnu.org Content-Type: multipart/mixed; boundary="000000000000bb42be057e1c8a01" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::132 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) --000000000000bb42be057e1c8a01 Content-Type: text/plain; charset="UTF-8" The man page description of the -I option implies that grep might output match information for a binary file if it hasn't "discovered" that the file is binary yet. It seems that even with -I Binary file matches may be reported, as this example on the attached file shows: $ 'grep' -I -e '.' bca9b83eeb33810a61cca0485f504f98540156 Binary file bca9b83eeb33810a61cca0485f504f98540156 matches This seems like a bug, because it's clearly produced at a point when grep has already decided the file is binary, and scripts can reasonably expect that any matches that do occur in a so-far-unknown-to-be-binary file will conform to the output format specified by other other options (e.g. -n) and feature an actual file name. Britton --000000000000bb42be057e1c8a01 Content-Type: application/octet-stream; name=bca9b83eeb33810a61cca0485f504f98540156 Content-Disposition: attachment; filename=bca9b83eeb33810a61cca0485f504f98540156 Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_jq8lexqw0 eAGlj0tOAzEQBVn7FH0BIv/anwhFEVuQWLBgGc3Y7cQKY49MR3B8BiFOwPLV4qkq9WWpDDrYOx5E oBFN1hiDV7kUZ0IKNmjjTZAl6jJjJB2dI7FOgxqD8ZSUp4DeZJtl9EpG5bGUSA4pzdb6mI1EMd34 0gc8jsrcGzxThycatcHD/It21595PC9Tfd+lvhxAocVNxWkJ9zJKKTa6yTL980bUlukLNgseU6LT Z+XLaR19/dj/9cBbH9fazvDK+eXG4hvxsVs+ --000000000000bb42be057e1c8a01-- ------------=_1548042302-22621-1--