Subject: Re: bug#21558: checking for a binary file is not deterministic

From: Paul Eggert <[email-masked]>
Date: Fri, 25 Sep 2015 12:17:57 -0700

On 09/25/2015 11:54 AM, Benno Schulenberg wrote:
> On Fri, Sep 25, 2015, at 20:02, Paul Eggert wrote:
>> Thanks for the bug report.  This appears to be basically the same as
>> Bug#20526.
> Well, not quite.  That grep will see misencoded files as binary data,
> I understand.  But what perplexed me is that grep would *sometimes*
> see the piped data as binary, and sometimes not.  How is this possible?

Grep reads the first buffer out of the pipe and decides based on that 
buffer whether the input is binary.  Due to timing issues the pipe's 
first buffer may contain more or fewer bytes, depending on the run.  The 
change proposed for Bug#20526 would change grep so that it uses a 
deterministic algorithm, independent of the number of bytes it happens 
to get in the first input buffer.

> If I understand it correctly, it would mean that in my example the
> piped data would never be classified as binary because the first
> grep will never output any of the misencoded bytes.  Right?
>

Yes, that's the idea.