grep inconsistency when used on binary files omitting -a

Bug #702690 reported by Imre Péntek
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
grep (Ubuntu)
New
Undecided
Unassigned

Bug Description

Binary package hint: grep

Hello. I am about to use grep from my script on a binary stdin. the result I intend to receive from grep is actually text, and in most cases I get the result I want, but in some cases grep only prints
Binary file (standard input) matches

so it's some sort of inconsistency.
Well, adding -a to the command line is not only a workaround, so I'll do it, however this fact doesn't mean this inconsistency isn't a bug. It seems to me that bash launches the processes in different order/parallelly/forked process so I believe it is triggered by an unfortunate outcome of a race condition.

I'll attach testfiles to this bug report tomorrow

ProblemType: Bug
DistroRelease: Ubuntu 10.04
Package: grep 2.5.4-4build1
ProcVersionSignature: Ubuntu 2.6.32-27.49-generic-pae 2.6.32.26+drm33.12
Uname: Linux 2.6.32-27-generic-pae i686
Architecture: i386
Date: Fri Jan 14 02:33:47 2011
InstallationMedia: Ubuntu 10.04 "Lucid Lynx" - Release Candidate i386 (20100419)
ProcEnviron:
 PATH=(custom, user)
 LANG=hu_HU.utf8
 SHELL=/bin/bash
SourcePackage: grep

Revision history for this message
Imre Péntek (pentek-imre) wrote :
Revision history for this message
Imre Péntek (pentek-imre) wrote :

I can reproduce the bug with this testscript. It generates a testfile (if it doesn't exist) from /dev/urandom, as I noticed there are testfiles better than other testfiles to reproduce the bug. So if you don't manage to reproduce the bug after several tries (say, 30, this would be more than enough) remove the testfile, so the script can generate a new one.

The script refers to one result as expected result, while refers to the other result as the illustration of the bug. It's just what I happened to expect when I wrote my previous script, I do not want to suggest what should be returned by grep consistently. But, what I want to suggest is the result here should be consistent (so always the "buggy" one, or always the "expected" one).
imi@most:/tmp/testdir$ ls -A
testscript.sh
imi@most:/tmp/testdir$ mcedit testscript.sh

imi@most:/tmp/testdir$ ./testscript.sh
got result: 19 -- expected result: 19
result is OK.
imi@most:/tmp/testdir$ ls -A
testfile testscript.sh
imi@most:/tmp/testdir$ ./testscript.sh
got result: 19 -- expected result: 19
result is OK.
imi@most:/tmp/testdir$ ./testscript.sh
got result: 49 -- expected result: 19
we've fetched the bug now!
please notice that 49 is the actual char count for the message (szabványos bemenet) bináris fájl illeszkedik
imi@most:/tmp/testdir$ rm testfile
imi@most:/tmp/testdir$ LANG=en_GB ./testscript.sh
got result: 37 -- expected result: 19
we've fetched the bug now!
please notice that 37 is the actual char count for the message Binary file (standard input) matches
imi@most:/tmp/testdir$ echo "Binary file (standard input) matches"|wc -c
37
imi@most:/tmp/testdir$ echo "(szabványos bemenet) bináris fájl illeszkedik"|wc -c
49
imi@most:/tmp/testdir$ LANG=en_GB ./testscript.sh
got result: 19 -- expected result: 19
result is OK.
imi@most:/tmp/testdir$

you can watch the same session as a video here: http://csomalin.csoma.elte.hu/~pentek_i/grep_bug.ogv

btw my default $LANG is:
imi@most:/tmp/testdir$ echo $LANG
hu_HU.utf8
imi@most:/tmp/testdir$

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.