Skip to content

Commit fdc3bd8

Browse files
committed
Warn instead of DIE when a repetition would exhaust RAM
For discussions on #23561. perl -e 'use warnings; my $x = ($_) ? "A" x (2**62) : "Z"' gives this on blead for me: ``` Out of memory! panic: fold_constants JMPENV_PUSH returned 2 at -e line 1. ``` on the previous commit, it would die: ``` Unrealistically large string repetition value" ``` With this commit, it just warns: ``` Unrealistically large string repetition value at -e line 1. ``` but will blow up if the repetition OP does get executed: ``` Out of memory in perl:util:safesysrealloc ```
1 parent 3725af9 commit fdc3bd8

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

op.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5025,20 +5025,19 @@ S_fold_constants(pTHX_ OP *const o)
50255025
if (SvIOKp(constsv)) {
50265026
if (SvIOK_UV(constsv)) {
50275027
if (SvUVX(constsv) > SIZE_MAX >> 2)
5028-
goto repetition_die;
5028+
ck_warner(packWARN(WARN_MISC), "Unrealistically large string repetition value");
50295029
if (SvUVX(constsv) > arbitrary)
50305030
goto nope;
50315031
} else {
50325032
if (SvIVX(constsv) > (IV)(SIZE_MAX >> 2))
5033-
goto repetition_die;
5033+
ck_warner(packWARN(WARN_MISC), "Unrealistically large string repetition value");
50345034
if (SvIVX(constsv) > (IV)arbitrary)
50355035
goto nope;
50365036
}
50375037
} else {
5038-
NV rhs = SvNV_nomg(constsv);
5039-
if (rhs > (NV)(SIZE_MAX >> 2)) {
5040-
repetition_die:
5041-
DIE(aTHX_ "Unrealistically large string repetition value");
5038+
NV rhs = 0.0; rhs = SvNV_nomg(constsv);
5039+
if (rhs >= (NV)((SIZE_MAX >> 2) +1) ) {
5040+
ck_warner(packWARN(WARN_MISC), "Unrealistically large string repetition value");
50425041
}
50435042
if (rhs > (NV)arbitrary)
50445043
goto nope;

pod/perldiag.pod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7387,7 +7387,7 @@ subroutine.
73877387

73887388
=item Unrealistically large string repetition value
73897389

7390-
The value of the right operand in the string repetition operator is
7390+
(W misc) The value of the right operand in the string repetition operator is
73917391
likely close to or will exceed the maximum memory allocation that
73927392
your system can provide.
73937393

0 commit comments

Comments
 (0)