From 389ecb564541f5a336b531db204970925ed27790 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Wed, 24 Jul 2013 14:23:54 -0700 Subject: [PATCH] Stop minlen regexp optimisation from rejecting long strings This fixes #112790 and part of #116907. The length of the string is cast to I32, so it wraps and end up less than the minimum length. For now, simply skip this optimisation if minlen itself wraps and becomes negative. --- MANIFEST | 1 + pp_hot.c | 2 +- t/bigmem/regexp.t | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 t/bigmem/regexp.t diff --git a/MANIFEST b/MANIFEST index 7ee5d51..45601d3 100644 --- a/MANIFEST +++ b/MANIFEST @@ -4939,6 +4939,7 @@ t/base/while.t See if while work t/benchmark/rt26188-speed-up-keys-on-empty-hash.t Benchmark if keys on empty hashes is fast enough t/bigmem/pos.t Check that pos() handles large offsets t/bigmem/read.t Check read() handles large offsets +t/bigmem/regexp.t Test regular expressions with large strings t/bigmem/vec.t Check vec() handles large offsets t/cmd/elsif.t See if else-if works t/cmd/for.t See if for loops work diff --git a/pp_hot.c b/pp_hot.c index afecce8..ca285e2 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1383,7 +1383,7 @@ PP(pp_match) rx = PM_GETRE(pm); } - if (RX_MINLEN(rx) > (I32)len) { + if (RX_MINLEN(rx) >= 0 && (STRLEN)RX_MINLEN(rx) > len) { DEBUG_r(PerlIO_printf(Perl_debug_log, "String shorter than min possible regex match\n")); goto nope; } diff --git a/t/bigmem/regexp.t b/t/bigmem/regexp.t new file mode 100644 index 0000000..ef029fb --- /dev/null +++ b/t/bigmem/regexp.t @@ -0,0 +1,22 @@ +#!perl +BEGIN { + chdir 't'; + unshift @INC, "../lib"; + require './test.pl'; +} + +use Config qw(%Config); + +$ENV{PERL_TEST_MEMORY} >= 2 + or skip_all("Need ~2Gb for this test"); +$Config{ptrsize} >= 8 + or skip_all("Need 64-bit pointers for this test"); + +plan(2); + +# [perl #116907] +# ${\2} to defeat constant folding, which in this case actually slows +# things down +my $x=" "x(${\2}**31); +ok $x =~ /./, 'match against long string succeeded'; +is "$-[0]-$+[0]", '0-1', '@-/@+ after match against long string'; -- 2.7.4