Commit 1ac3f11183 for perl
commit 1ac3f111830e8f24ffd2291b619ff28421dc0ca4
Author: Steve Hay <steve.m.hay@googlemail.com>
Date: Sat Nov 21 17:11:28 2026 +0000
Update Text-Balanced from 2.07 to 2.08
diff --git a/MANIFEST b/MANIFEST
index 61b8fceaa6..aa8ec59e6c 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -3179,11 +3179,7 @@ cpan/Text-Balanced/t/06_extqlk.t See if Text::Balanced works
cpan/Text-Balanced/t/07_exttag.t See if Text::Balanced works
cpan/Text-Balanced/t/08_extvar.t See if Text::Balanced works
cpan/Text-Balanced/t/09_gentag.t See if Text::Balanced works
-cpan/Text-Balanced/t/94_changes.t
-cpan/Text-Balanced/t/95_critic.t
-cpan/Text-Balanced/t/96_pmv.t
-cpan/Text-Balanced/t/97_pod.t
-cpan/Text-Balanced/t/98_pod_coverage.t
+cpan/Text-Balanced/t/10_depth.t See if Text::Balanced works
cpan/Text-ParseWords/lib/Text/ParseWords.pm Perl module to split words on arbitrary delimiter
cpan/Text-ParseWords/t/ParseWords.t See if Text::ParseWords works
cpan/Text-ParseWords/t/taint.t See if Text::ParseWords works with tainting
diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl
index 45046307e8..4c5c38f295 100755
--- a/Porting/Maintainers.pl
+++ b/Porting/Maintainers.pl
@@ -1156,8 +1156,16 @@ our %Modules = (
},
'Text::Balanced' => {
- 'DISTRIBUTION' => 'SHAY/Text-Balanced-2.07.tar.gz',
+ 'DISTRIBUTION' => 'SHAY/Text-Balanced-2.08.tar.gz',
'FILES' => q[cpan/Text-Balanced],
+ 'EXCLUDED' => [
+ qw( t/94_changes.t
+ t/95_critic.t
+ t/96_pmv.t
+ t/97_pod.t
+ t/98_pod_coverage.t
+ ),
+ ],
},
'Text::ParseWords' => {
diff --git a/cpan/Text-Balanced/lib/Text/Balanced.pm b/cpan/Text-Balanced/lib/Text/Balanced.pm
index 0b33c789cb..e6a68b7348 100644
--- a/cpan/Text-Balanced/lib/Text/Balanced.pm
+++ b/cpan/Text-Balanced/lib/Text/Balanced.pm
@@ -1,6 +1,6 @@
# Copyright (C) 1997-2001 Damian Conway. All rights reserved.
# Copyright (C) 2009 Adam Kennedy.
-# Copyright (C) 2015, 2022 Steve Hay and other contributors. All rights
+# Copyright (C) 2015, 2022, 2026 Steve Hay and other contributors. All rights
# reserved.
# This module is free software; you can redistribute it and/or modify it under
@@ -18,7 +18,7 @@ use Exporter ();
use vars qw { $VERSION @ISA %EXPORT_TAGS };
BEGIN {
- $VERSION = '2.07';
+ $VERSION = '2.08';
@ISA = 'Exporter';
%EXPORT_TAGS = (
ALL => [ qw{
@@ -55,6 +55,9 @@ our $RE_NUM = qr/\s*[+\-.0-9][+\-.0-9e]*/i; # numerical constant
our %ref2slashvalid; # is quotelike /.../ pattern valid here for given textref?
our %ref2qmarkvalid; # is quotelike ?...? pattern valid here for given textref?
+our $MAX_DEPTH = 10_000; # maximum recursion depth for _match_codeblock/_match_tagged
+our $_depth = 0; # current recursion depth (localised on each recursive entry)
+
# HANDLE RETURN VALUES IN VARIOUS CONTEXTS
sub _failmsg {
@@ -338,6 +341,11 @@ sub extract_tagged (;$$$$$) # ($text, $opentag, $closetag, $pre, \%options)
sub _match_tagged # ($$$$$$$)
{
my ($textref, $pre, $ldel, $rdel, $omode, $bad, $ignore) = @_;
+ local $_depth = $_depth + 1;
+ if ($_depth > $MAX_DEPTH) {
+ _failmsg "Recursion limit ($MAX_DEPTH) exceeded in _match_tagged", pos $$textref;
+ goto failed;
+ }
my $rdelspec;
my ($startpos, $opentagpos, $textpos, $parapos, $closetagpos, $endpos) = ( pos($$textref) = pos($$textref)||0 );
@@ -567,6 +575,11 @@ sub extract_codeblock (;$$$$$)
sub _match_codeblock
{
my ($textref, $pre, $ldel_outer, $rdel_outer, $ldel_inner, $rdel_inner, $rd, $no_backcompat) = @_;
+ local $_depth = $_depth + 1;
+ if ($_depth > $MAX_DEPTH) {
+ _failmsg "Recursion limit ($MAX_DEPTH) exceeded in _match_codeblock", pos $$textref;
+ return;
+ }
$rdel_outer = qr/\G\s*($rdel_outer)/ if !$no_backcompat; # Switch calls this func directly
my $startpos = pos($$textref) = pos($$textref) || 0;
unless ($$textref =~ m/$pre/gc)
@@ -1005,8 +1018,10 @@ sub extract_multiple (;$$$$) # ($text, $functions_ref, $max_fields, $ignoreun
{
$unkpos = pos($$textref)-1
unless $igunk || defined $unkpos;
- _update_patvalid($textref, substr $$textref, defined $unkpos ? $unkpos : 0,
- pos($$textref) - (defined $unkpos ? $unkpos : 0));
+ my $curpos = pos($$textref);
+ my $tailstart = $curpos > 10 ? $curpos - 10 : 0;
+ _update_patvalid($textref, substr $$textref, $tailstart,
+ $curpos - $tailstart);
}
}
@@ -2178,6 +2193,27 @@ That name may still be used, but is now deprecated.
=back
+=head1 CONFIGURATION VARIABLES
+
+=over 4
+
+=item C<$Text::Balanced::MAX_DEPTH>
+
+Controls the maximum recursion depth permitted when matching nested constructs
+in C<extract_codeblock> and C<extract_tagged>. The default is 10,000.
+
+If the input contains more levels of nesting than this limit, the extraction
+fails gracefully (returning C<undef> in scalar context, or a list whose first
+element is C<undef> in list context) rather than consuming unbounded memory.
+
+Callers that need to handle unusually deep but legitimate nesting can raise the
+limit before calling:
+
+ local $Text::Balanced::MAX_DEPTH = 50_000;
+ my ($extracted) = extract_codeblock($text);
+
+=back
+
=head1 DIAGNOSTICS
In a list context, all the functions return C<(undef,$original_text)>
@@ -2308,6 +2344,13 @@ C<extract_tagged> reached the end of the text without finding a closing tag
to match the original opening tag (and the failure mode was not
"MAX" or "PARA").
+=item C<Recursion limit (%d) exceeded in %s>
+
+The input contained more levels of nesting than allowed by
+C<$Text::Balanced::MAX_DEPTH>. The affected function is named in the message
+(C<_match_codeblock> or C<_match_tagged>). See L</"CONFIGURATION VARIABLES">
+for how to raise the limit if the input is legitimately deeply nested.
+
=back
=head1 EXPORTS
@@ -2409,8 +2452,8 @@ Copyright (C) 1997-2001 Damian Conway. All rights reserved.
Copyright (C) 2009 Adam Kennedy.
-Copyright (C) 2015, 2020, 2022 Steve Hay and other contributors. All rights
-reserved.
+Copyright (C) 2015, 2020, 2022, 2026 Steve Hay and other contributors. All
+rights reserved.
=head1 LICENCE
@@ -2420,11 +2463,11 @@ License or the Artistic License, as specified in the F<LICENCE> file.
=head1 VERSION
-Version 2.07
+Version 2.08
=head1 DATE
-08 Aug 2025
+21 Nov 2026
=head1 HISTORY
diff --git a/cpan/Text-Balanced/t/05_extmul.t b/cpan/Text-Balanced/t/05_extmul.t
index 9b612dc253..47025dab89 100644
--- a/cpan/Text-Balanced/t/05_extmul.t
+++ b/cpan/Text-Balanced/t/05_extmul.t
@@ -376,4 +376,42 @@ expect [ extract_multiple($slashmatch, [
]) ],
[ '$_', ' = 1 unless defined ', '$_', ' and ', '/\\d\\b/', ";\n" ];
+# extract_multiple was O(n^2) on unmatched text because _update_patvalid was
+# called with the entire growing unmatched prefix on each step. Verify the fix
+# does not regress the slash-validity tracking through a long unmatched run, and
+# that the performance is now linear.
+
+# Correctness: a /regex/ after a long run of unmatched text followed by "!~"
+# must still be recognised as a regex, not division.
+my $long_unmatched = 'x' x 50;
+my $long_slashmatch = "\$v = 1; ${long_unmatched} \$v !~ /abc/;";
+expect [ extract_multiple($long_slashmatch, [
+ \&extract_variable,
+ \&extract_quotelike,
+]) ],
+ [ '$v', " = 1; ${long_unmatched} ", '$v', ' !~ ', '/abc/', ';' ];
+
+# Correctness: same through a long run followed by "and"
+$long_slashmatch = "\$v = 1; ${long_unmatched} \$v and /abc/;";
+expect [ extract_multiple($long_slashmatch, [
+ \&extract_variable,
+ \&extract_quotelike,
+]) ],
+ [ '$v', " = 1; ${long_unmatched} ", '$v', ' and ', '/abc/', ';' ];
+
+# Performance: with quadratic behaviour, 64,000 bytes of unmatched input would
+# take ~800s (scaling from the reported ~20s at 8,000 bytes). With the fix it
+# completes in milliseconds. A 30-second limit is safe even on a heavily loaded
+# machine -- the gap between the expected (ms) and quadratic (~800s) outcomes is
+# too wide for load to bridge.
+# Use a no-op extractor to isolate the _update_patvalid fix from any separate
+# performance characteristics of the default extractors.
+{
+ use Time::HiRes qw(time);
+ my $t = time();
+ extract_multiple('z' x 64_000, [sub { () }]);
+ my $elapsed = time() - $t;
+ ok $elapsed < 30, "extract_multiple completes in reasonable time on long unmatched input (${elapsed}s)";
+}
+
done_testing;
diff --git a/cpan/Text-Balanced/t/10_depth.t b/cpan/Text-Balanced/t/10_depth.t
new file mode 100644
index 0000000000..d1b9df4044
--- /dev/null
+++ b/cpan/Text-Balanced/t/10_depth.t
@@ -0,0 +1,175 @@
+#!perl
+#===============================================================================
+#
+# t/10_depth.t
+#
+# DESCRIPTION
+# Test script for the $MAX_DEPTH recursion guard.
+# _match_codeblock and _match_tagged each track recursion depth via
+# $Text::Balanced::_depth (localised on entry) and fail when it exceeds
+# $Text::Balanced::MAX_DEPTH.
+#
+# extract_tagged propagates failure (undef) cleanly when the depth limit is
+# hit, so its boundary is exactly MAX_DEPTH + 1 levels.
+#
+# extract_codeblock's internal loop can return a truncated match for inputs
+# slightly above MAX_DEPTH (the outer levels succeed; the inner levels that
+# hit the guard are treated as unmatched plain text). Failure (undef) is
+# guaranteed for inputs sufficiently larger than MAX_DEPTH. We test both the
+# "succeeds at the limit" and "fails well above the limit" cases.
+#
+# COPYRIGHT
+# Copyright (C) 2026 Steve Hay. All rights reserved.
+#
+# LICENCE
+# This script is free software; you can redistribute it and/or modify it under
+# the same terms as Perl itself, i.e. under the terms of either the GNU
+# General Public License or the Artistic License, as specified in the LICENCE
+# file.
+#
+#===============================================================================
+
+use 5.008001;
+
+use strict;
+use warnings;
+
+use Test::More;
+use Text::Balanced qw(extract_codeblock extract_tagged);
+
+#===============================================================================
+# SUBROUTINES
+#===============================================================================
+
+sub make_nested_code {
+ my ($depth) = @_;
+ # No spaces between braces so each inner '{' triggers a recursive call.
+ return ('{' x $depth) . ('}' x $depth);
+}
+
+sub make_nested_tag {
+ my ($depth) = @_;
+ return ('<A>' x $depth) . 'x' . ('</A>' x $depth);
+}
+
+#===============================================================================
+# MAIN PROGRAM
+#===============================================================================
+
+# -------------------------------------------------------------------------
+# extract_codeblock
+# -------------------------------------------------------------------------
+
+{
+ local $Text::Balanced::MAX_DEPTH = 10;
+
+ # Nesting at or below the limit must succeed and return the full match.
+ for my $n (1, 5, 10) {
+ my $text = make_nested_code($n);
+ my ($match) = extract_codeblock($text);
+ ok defined($match), "extract_codeblock: $n levels of nesting succeeds";
+ is length($match), $n * 2, "extract_codeblock: $n levels returns full match";
+ is $@, undef, "extract_codeblock: no error at $n levels";
+ }
+
+ # Well above the limit the call must fail (return undef).
+ # (Inputs only slightly above MAX_DEPTH may return a truncated match as
+ # the guard fires deep in the call stack and outer levels partially
+ # succeed; inputs much larger than MAX_DEPTH fail completely.)
+ for my $n (100, 500) {
+ my $text = make_nested_code($n);
+ my ($match) = extract_codeblock($text);
+ ok !defined($match), "extract_codeblock: $n levels of nesting fails";
+ ok defined($@), "extract_codeblock: \$@ is set at $n levels";
+ }
+
+ # $_depth resets between calls: a failed call must not leave residue that
+ # causes a subsequent valid call to fail.
+ {
+ my $deep = make_nested_code(100);
+ extract_codeblock($deep); # expected to fail
+
+ my $shallow = '{}';
+ my ($match) = extract_codeblock($shallow);
+ ok defined($match), 'extract_codeblock: $_depth resets after a failed call';
+ }
+}
+
+# Default MAX_DEPTH is restored after the local block.
+is $Text::Balanced::MAX_DEPTH, 10_000,
+ 'extract_codeblock: MAX_DEPTH restored to default after local override';
+
+# Raising MAX_DEPTH allows previously-failing depths to succeed.
+{
+ local $Text::Balanced::MAX_DEPTH = 20;
+
+ my $text = make_nested_code(20);
+ my ($match) = extract_codeblock($text);
+ ok defined($match), 'extract_codeblock: 20 levels succeeds with MAX_DEPTH=20';
+ is length($match), 40, 'extract_codeblock: 20 levels returns full match with MAX_DEPTH=20';
+
+ my $big = make_nested_code(500);
+ ($match) = extract_codeblock($big);
+ ok !defined($match), 'extract_codeblock: 500 levels still fails with MAX_DEPTH=20';
+}
+
+# -------------------------------------------------------------------------
+# extract_tagged
+# -------------------------------------------------------------------------
+
+{
+ local $Text::Balanced::MAX_DEPTH = 10;
+
+ # Nesting at or below the limit must succeed.
+ for my $n (1, 5, 10) {
+ my $text = make_nested_tag($n);
+ my ($match) = extract_tagged($text, '<A>', '</A>');
+ ok defined($match), "extract_tagged: $n levels of nesting succeeds";
+ is $@, undef, "extract_tagged: no error at $n levels";
+ }
+
+ # extract_tagged propagates failure cleanly: the boundary is exactly
+ # MAX_DEPTH + 1 (= 11 with MAX_DEPTH=10).
+ {
+ my $text = make_nested_tag(11);
+ my ($match) = extract_tagged($text, '<A>', '</A>');
+ ok !defined($match), 'extract_tagged: MAX_DEPTH+1 levels of nesting fails';
+ ok defined($@), 'extract_tagged: $@ is set when depth exceeded';
+ }
+
+ for my $n (20, 100) {
+ my $text = make_nested_tag($n);
+ my ($match) = extract_tagged($text, '<A>', '</A>');
+ ok !defined($match), "extract_tagged: $n levels of nesting fails";
+ }
+
+ # $_depth resets between calls.
+ {
+ my $deep = make_nested_tag(100);
+ extract_tagged($deep, '<A>', '</A>'); # expected to fail
+
+ my $shallow = '<A>x</A>';
+ my ($match) = extract_tagged($shallow, '<A>', '</A>');
+ ok defined($match), 'extract_tagged: $_depth resets after a failed call';
+ }
+}
+
+is $Text::Balanced::MAX_DEPTH, 10_000,
+ 'extract_tagged: MAX_DEPTH restored to default after local override';
+
+# Raising MAX_DEPTH allows previously-failing depths to succeed.
+{
+ local $Text::Balanced::MAX_DEPTH = 20;
+
+ my $text = make_nested_tag(20);
+ my ($match) = extract_tagged($text, '<A>', '</A>');
+ ok defined($match), 'extract_tagged: 20 levels succeeds with MAX_DEPTH=20';
+
+ my $text21 = make_nested_tag(21);
+ ($match) = extract_tagged($text21, '<A>', '</A>');
+ ok !defined($match), 'extract_tagged: 21 levels fails with MAX_DEPTH=20';
+}
+
+done_testing;
+
+#===============================================================================
diff --git a/cpan/Text-Balanced/t/94_changes.t b/cpan/Text-Balanced/t/94_changes.t
deleted file mode 100644
index 400ec89093..0000000000
--- a/cpan/Text-Balanced/t/94_changes.t
+++ /dev/null
@@ -1,48 +0,0 @@
-#!perl
-#===============================================================================
-#
-# t/94_changes.t
-#
-# DESCRIPTION
-# Test script to check CPAN::Changes conformance.
-#
-# COPYRIGHT
-# Copyright (C) 2015 Steve Hay. All rights reserved.
-#
-# LICENCE
-# This script is free software; you can redistribute it and/or modify it under
-# the same terms as Perl itself, i.e. under the terms of either the GNU
-# General Public License or the Artistic License, as specified in the LICENCE
-# file.
-#
-#===============================================================================
-
-use 5.008001;
-
-use strict;
-use warnings;
-
-use Test::More;
-
-#===============================================================================
-# MAIN PROGRAM
-#===============================================================================
-
-MAIN: {
- plan skip_all => 'Author testing only' unless $ENV{AUTHOR_TESTING};
-
- my $ok = eval {
- require Test::CPAN::Changes;
- Test::CPAN::Changes->import();
- 1;
- };
-
- if (not $ok) {
- plan skip_all => 'Test::CPAN::Changes required to test Changes';
- }
- else {
- changes_ok();
- }
-}
-
-#===============================================================================
diff --git a/cpan/Text-Balanced/t/95_critic.t b/cpan/Text-Balanced/t/95_critic.t
deleted file mode 100644
index 1e575423eb..0000000000
--- a/cpan/Text-Balanced/t/95_critic.t
+++ /dev/null
@@ -1,48 +0,0 @@
-#!perl
-#===============================================================================
-#
-# t/95_critic.t
-#
-# DESCRIPTION
-# Test script to check Perl::Critic conformance.
-#
-# COPYRIGHT
-# Copyright (C) 2015 Steve Hay. All rights reserved.
-#
-# LICENCE
-# This script is free software; you can redistribute it and/or modify it under
-# the same terms as Perl itself, i.e. under the terms of either the GNU
-# General Public License or the Artistic License, as specified in the LICENCE
-# file.
-#
-#===============================================================================
-
-use 5.008001;
-
-use strict;
-use warnings;
-
-use Test::More;
-
-#===============================================================================
-# MAIN PROGRAM
-#===============================================================================
-
-MAIN: {
- plan skip_all => 'Author testing only' unless $ENV{AUTHOR_TESTING};
-
- my $ok = eval {
- require Test::Perl::Critic;
- Test::Perl::Critic->import(-profile => '');
- 1;
- };
-
- if (not $ok) {
- plan skip_all => 'Test::Perl::Critic required to test with Perl::Critic';
- }
- else {
- all_critic_ok('.');
- }
-}
-
-#===============================================================================
diff --git a/cpan/Text-Balanced/t/96_pmv.t b/cpan/Text-Balanced/t/96_pmv.t
deleted file mode 100644
index e1197da5de..0000000000
--- a/cpan/Text-Balanced/t/96_pmv.t
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/usr/bin/perl
-
-# Test that our declared minimum Perl version matches our syntax
-
-use 5.008001;
-
-use strict;
-use warnings;
-
-use Test::More;
-
-my @MODULES = (
- 'Perl::MinimumVersion 1.20',
- 'Test::MinimumVersion 0.101082',
-);
-
-# Don't run tests for installs
-use Test::More;
-unless ( $ENV{AUTHOR_TESTING} ) {
- plan( skip_all => "Author testing only" );
-}
-
-# Load the testing modules
-foreach my $MODULE ( @MODULES ) {
- ## no critic (BuiltinFunctions::ProhibitStringyEval)
- eval "use $MODULE";
- if ( $@ ) {
- plan( skip_all => "$MODULE not available for testing" );
- }
-}
-
-all_minimum_version_from_mymetayml_ok();
diff --git a/cpan/Text-Balanced/t/97_pod.t b/cpan/Text-Balanced/t/97_pod.t
deleted file mode 100644
index d0f4caec64..0000000000
--- a/cpan/Text-Balanced/t/97_pod.t
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/usr/bin/perl
-
-# Test that the syntax of our POD documentation is valid
-
-use 5.008001;
-
-use strict;
-use warnings;
-
-use Test::More;
-
-my @MODULES = (
- 'Pod::Simple 3.07',
- 'Test::Pod 1.26',
-);
-
-# Don't run tests for installs
-use Test::More;
-unless ( $ENV{AUTHOR_TESTING} ) {
- plan( skip_all => "Author testing only" );
-}
-
-# Load the testing modules
-foreach my $MODULE ( @MODULES ) {
- ## no critic (BuiltinFunctions::ProhibitStringyEval)
- eval "use $MODULE";
- if ( $@ ) {
- plan( skip_all => "$MODULE not available for testing" );
- }
-}
-
-all_pod_files_ok();
diff --git a/cpan/Text-Balanced/t/98_pod_coverage.t b/cpan/Text-Balanced/t/98_pod_coverage.t
deleted file mode 100644
index cce4f94c60..0000000000
--- a/cpan/Text-Balanced/t/98_pod_coverage.t
+++ /dev/null
@@ -1,51 +0,0 @@
-#!perl
-#===============================================================================
-#
-# t/99_pod_coverage.t
-#
-# DESCRIPTION
-# Test script to check POD coverage.
-#
-# COPYRIGHT
-# Copyright (C) 2015 Steve Hay. All rights reserved.
-#
-# LICENCE
-# This script is free software; you can redistribute it and/or modify it under
-# the same terms as Perl itself, i.e. under the terms of either the GNU
-# General Public License or the Artistic License, as specified in the LICENCE
-# file.
-#
-#===============================================================================
-
-use 5.008001;
-
-use strict;
-use warnings;
-
-use Test::More;
-
-#===============================================================================
-# MAIN PROGRAM
-#===============================================================================
-
-MAIN: {
- plan skip_all => 'Author testing only' unless $ENV{AUTHOR_TESTING};
-
- my $ok = eval {
- require Test::Pod::Coverage;
- Test::Pod::Coverage->import();
- 1;
- };
-
- if (not $ok) {
- plan skip_all => 'Test::Pod::Coverage required to test POD coverage';
- }
- elsif ($Test::Pod::Coverage::VERSION < 0.08) {
- plan skip_all => 'Test::Pod::Coverage 0.08 or higher required to test POD coverage';
- }
- else {
- all_pod_coverage_ok();
- }
-}
-
-#===============================================================================