Subject: bug#15759: closed (Re: bug#15758: grep 2.15 calls abort() on larger searches with -P)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 13 Dec 2013 18:34:04 +0000

Your bug report

#15758: regression in grep 2.15 with PCRE searches

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 [email-masked].

-- 
15758: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15758
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#15758: grep 2.15 calls abort() on larger searches with -P
From: Jim Meyering <[email-masked]>
To: Santiago <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Fri, 13 Dec 2013 10:33:35 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

On Tue, Nov 26, 2013 at 6:30 AM, Santiago <[email-masked]> wrote:
> This bug was also reported in Debian ( http://bugs.debian.org/730472 ).
>
> Taking a look on it, I think the most suitable solution for the moment
> is to flag PCRE_NO_UTF8_CHECK instead of PCRE_UTF8, so
> PCRE does not check if inputs are UTF8 valid. Resulting behavior is
> similar to pre-grep-2.15. (See 15758-PCRE-no-check-UTF8.patch)

Thanks for the suggested patches and report.  Your first patch is
almost right.  The problem is that we cannot remove the PCRE_UTF8 flag.
If we did that, it would disable UTF-8, reverting an older fix.
See tests/pcre-utf8 for examples, or run this:

  printf '\342\202\254\n' | LC_ALL=en_US.UTF-8 src/grep -P '^\p{S}'

I've added a commit log, improved a related test and attached
a slightly different patch, but left you as the "Author".
I'll wait for an explicit ACK before pushing it.

With that, there is no need to handle PCRE_ERROR_BADUTF8
because that should not happen.

Subject: regression in grep 2.15 with PCRE searches
From: Dave Reisner <[email-masked]>
To: [email-masked]
Date: Wed, 30 Oct 2013 13:23:10 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi,

A user reported a regression in grep 2.15 which is easily reproducible
as ``grep -P foo /bin/mount''. The root cause is that pcre_exec is
returning PCRE_ERROR_BADUTF8 when the current locale supports UTF-8.
This is unhandled by grep and causes it to call abort().

I bisected the breakage to commit 67436786c110bb which essentially
introduces UTF-8 validation for all searched data. In a large number of
file hierarchies, one may easily hit this via a recursive search.

I crafted the following inline diff which fixes the problem. While I'm
not sure of its correctness, it at least describes one possible fix.

  diff --git a/src/pcresearch.c b/src/pcresearch.c
  index ad5999d..ce55ab3 100644
  --- a/src/pcresearch.c
  +++ b/src/pcresearch.c
  @@ -176,6 +176,9 @@ Pexecute (char const *buf, size_t size, size_t *match_size,
         switch (e)
           {
           case PCRE_ERROR_NOMATCH:
  +#ifdef HAVE_LANGINFO_CODESET
  +        case PCRE_ERROR_BADUTF8:
  +#endif
             return -1;

           case PCRE_ERROR_NOMEMORY:

Cheers,
Dave