Skip to content

Commit 034aa30

Browse files
committed
Force disable LEAVE_SRC in $PerlIO::encoding::fallback
Setting $PerlIO::encoding::fallback to any value containing LEAVE_SRC will result in an infinite loop of the first buffer of input. This is never desirable.
1 parent 370c6ab commit 034aa30

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ext/PerlIO-encoding/encoding.xs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
#define OUR_DEFAULT_FB "Encode::PERLQQ"
88
#define OUR_STOP_AT_PARTIAL "Encode::STOP_AT_PARTIAL"
9+
#define OUR_LEAVE_SRC "Encode::LEAVE_SRC"
910

1011
/* This will be set during BOOT */
1112
static unsigned int encode_stop_at_partial = 0;
13+
static unsigned int encode_leave_src = 0;
1214

1315
#if defined(USE_PERLIO)
1416

@@ -170,7 +172,7 @@ PerlIOEncode_pushed(pTHX_ PerlIO * f, const char *mode, SV * arg, PerlIO_funcs *
170172
e->chk = newSVsv(get_sv("PerlIO::encoding::fallback", 0));
171173
if (SvROK(e->chk))
172174
Perl_croak(aTHX_ "PerlIO::encoding::fallback must be an integer");
173-
SvUV_set(e->chk, SvUV(e->chk) | encode_stop_at_partial);
175+
SvUV_set(e->chk, SvUV(e->chk) & ~encode_leave_src | encode_stop_at_partial);
174176
e->inEncodeCall = 0;
175177

176178
FREETMPS;
@@ -667,6 +669,15 @@ BOOT:
667669
SPAGAIN;
668670
encode_stop_at_partial = POPu;
669671

672+
PUSHMARK(sp);
673+
PUTBACK;
674+
if (call_pv(OUR_LEAVE_SRC, G_SCALAR) != 1) {
675+
/* should never happen */
676+
Perl_die(aTHX_ "%s did not return a value", OUR_LEAVE_SRC);
677+
}
678+
SPAGAIN;
679+
encode_leave_src = POPu;
680+
670681
PUTBACK;
671682
#ifdef PERLIO_LAYERS
672683
PerlIO_define_layer(aTHX_ PERLIO_FUNCS_CAST(&PerlIO_encode));

0 commit comments

Comments
 (0)