Subject: segmentation fault if input line is too long

From: Holger Then <[email-masked]>
Date: Thu, 26 Sep 2013 14:21:54 +0200 (CEST)

If grep searches through a line that is longer than
INT_MAX (= 2147483647) characters, then grep causes
a segmentation fault.

Interestingly this bug does not occur with fgrep or
with grep -F

Kind regards,
Holger

$ wc grep_bug.txt
          1   12200610 3281667946 grep_bug.txt
$ fgrep -e 1 grep_bug.txt | wc
       1 12200610 3281667946
$ grep -Fe 1 grep_bug.txt | wc
       1 12200610 3281667946
$ grep -e 1 grep_bug.txt | wc
       0       0       0
$ grep -e 1 grep_bug.txt
Segmentation fault

$ tail -c 2147483647 grep_bug.txt | grep -e 1 | wc
       1 8385663 2147483647
$ tail -c 2147483648 grep_bug.txt | grep -e 1 | wc
       0       0       0
$ tail -c 2147483648 grep_bug.txt | grep -e 1
Segmentation fault

$ uname 
-a
Linux c-0-0.local 2.6.32-358.11.1.el6.x86_64 #1 SMP Wed Jun 12 03:34:52 
UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
$ grep --version
GNU grep 2.6.3

Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.