Permalink
Browse files

Change REG_INFTY to 2**16-1, instead of 2**15-1

This commit doubles the upper limit that unbounded regular expression
quantifiers can match up to.  Things like {m,} "+" and "*" now can match
up to U16_MAX times.

We probably should make this a 32 bit value, but doing this doubling was
easy and has fewer potential implications.

See http://nntp.perl.org/group/perl.perl5.porters/251413 and
followups
  • Loading branch information...
khwilliamson committed Sep 30, 2018
1 parent 3f4fa0e commit feb2ac770e7eee924815c7ae69d56a0be5abab4c
Showing with 15 additions and 9 deletions.
  1. +6 −0 pod/perldelta.pod
  2. +7 −7 regcomp.h
  3. +1 −1 t/re/pat.t
  4. +1 −1 t/re/reg_mesg.t
View
@@ -27,6 +27,12 @@ here, but most should go in the L</Performance Enhancements> section.
[ List each enhancement as a =head2 entry ]
=head2 The maximum number of times a pattern can match has been doubled
to 65535
This means if you specify C<qr/a+/> that there can be anywhere from 1
through 65535 C<"a">'s in a row, instead of 32267 as previously.
=head1 Security
XXX Any security-related notices go here. In particular, any security
View
@@ -265,22 +265,22 @@ struct regnode_ssc {
Impose a limit of REG_INFTY on various pattern matching operations
to limit stack growth and to avoid "infinite" recursions.
*/
/* The default size for REG_INFTY is I16_MAX, which is the same as
SHORT_MAX (see perl.h). Unfortunately I16 isn't necessarily 16 bits
(see handy.h). On the Cray C90, sizeof(short)==4 and hence I16_MAX is
((1<<31)-1), while on the Cray T90, sizeof(short)==8 and I16_MAX is
((1<<63)-1). To limit stack growth to reasonable sizes, supply a
/* The default size for REG_INFTY is U16_MAX, which is the same as
USHORT_MAX (see perl.h). Unfortunately U16 isn't necessarily 16 bits
(see handy.h). On the Cray C90, sizeof(short)==4 and hence U16_MAX is
((1<<32)-1), while on the Cray T90, sizeof(short)==8 and U16_MAX is
((1<<64)-1). To limit stack growth to reasonable sizes, supply a
smaller default.
--Andy Dougherty 11 June 1998
*/
#if SHORTSIZE > 2
# ifndef REG_INFTY
# define REG_INFTY ((1<<15)-1)
# define REG_INFTY ((1<<16)-1)
# endif
#endif
#ifndef REG_INFTY
# define REG_INFTY I16_MAX
# define REG_INFTY U16_MAX
#endif
#define ARG_VALUE(arg) (arg)
View
@@ -319,7 +319,7 @@ sub run_tests {
# Defaults assumed if this fails
eval { require Config; };
$::reg_infty = $Config::Config{reg_infty} // 32767;
$::reg_infty = $Config::Config{reg_infty} // 65535;
$::reg_infty_m = $::reg_infty - 1;
$::reg_infty_p = $::reg_infty + 1;
$::reg_infty_m = $::reg_infty_m; # Suppress warning.
View
@@ -102,7 +102,7 @@ sub mark_as_utf8 {
return @ret;
}
my $inf_m1 = ($Config::Config{reg_infty} || 32767) - 1;
my $inf_m1 = ($Config::Config{reg_infty} || 65535) - 1;
my $inf_p1 = $inf_m1 + 2;
my $B_hex = sprintf("\\x%02X", ord "B");

0 comments on commit feb2ac7

Please sign in to comment.