[3611] | 1 | #!/bin/sh
|
---|
| 2 | # Test regex on input buffers larger than 2GB
|
---|
| 3 |
|
---|
| 4 | # Copyright (C) 2018-2022 Free Software Foundation, Inc.
|
---|
| 5 |
|
---|
| 6 | # This program is free software: you can redistribute it and/or modify
|
---|
| 7 | # it under the terms of the GNU General Public License as published by
|
---|
| 8 | # the Free Software Foundation, either version 3 of the License, or
|
---|
| 9 | # (at your option) any later version.
|
---|
| 10 |
|
---|
| 11 | # This program is distributed in the hope that it will be useful,
|
---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | # GNU General Public License for more details.
|
---|
| 15 |
|
---|
| 16 | # You should have received a copy of the GNU General Public License
|
---|
| 17 | # along with this program. If not, see <https://www.gnu.org/licenses/>.
|
---|
| 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
|
---|
| 19 | very_expensive_
|
---|
| 20 | print_ver_ sed
|
---|
| 21 |
|
---|
| 22 | # Create a file larger than 2GB and containing a single line
|
---|
| 23 | # (resulting in a regex match against the entire file)
|
---|
| 24 | #
|
---|
| 25 | # This is a "very expensive" test, we can assume it is only run by
|
---|
| 26 | # developers or advanced users, and we can assume truncate(1) exists.
|
---|
| 27 | #
|
---|
| 28 | # On most modern file-systems, the file will be sparse and would not
|
---|
| 29 | # consume 2GB of physical storage.
|
---|
| 30 |
|
---|
| 31 | truncate -s 1G input || framework_failure_
|
---|
| 32 | printf aaaa >> input || framework_failure_
|
---|
| 33 | truncate -s +1G input || framework_failure_
|
---|
| 34 | printf 'a\n' >> input || framework_failure_
|
---|
| 35 |
|
---|
| 36 | # The expected error message
|
---|
| 37 | cat <<\EOF > exp-err1 || framework_failure_
|
---|
| 38 | sed: regex input buffer length larger than INT_MAX
|
---|
| 39 | EOF
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | # Before sed-4.5, this was silently a no-op: would not perform the subsitution
|
---|
| 43 | # but would not indicate any error either (https://bugs.gnu.org/30520).
|
---|
| 44 | # Exit code 4 is "panic".
|
---|
| 45 | returns_ 4 sed 's/a/b/g' input >/dev/null 2>err1 || fail=1
|
---|
| 46 | compare_ exp-err1 err1 || fail=1
|
---|
| 47 |
|
---|
| 48 | Exit $fail
|
---|