Skip to content

Commit 033a494

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 033a494

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
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;

0 commit comments

Comments
 (0)