This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Push a new stack in sv_recode_to_utf8
authorFather Chrysostomos <sprout@cpan.org>
Sat, 23 Nov 2013 04:34:17 +0000 (20:34 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 23 Nov 2013 05:20:37 +0000 (21:20 -0800)
That prevents this from happening under STRESS_REALLOC:

$ ./perl -Ilib -Mencoding=johab -e '(chr(0x7f) eq "\x7f")'
Use of the encoding pragma is deprecated at -e line 0.
perl(3939) malloc: *** error for object 0x7fac20c03968: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

(That is an excerpt from t/uni/chr.t.)

It may also fix other instances of encoding.pm crashing, which I had
almost vowed not to do.  Oh well.

Constant folding is generally expected not to reallocate the stack,
because it should never need to extend it, just reduce the number of
items on it.

sv_recode_to_utf8 breaks that assumption.

sv.c

diff --git a/sv.c b/sv.c
index 2c83597..1c22615 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -14072,6 +14072,7 @@ Perl_sv_recode_to_utf8(pTHX_ SV *sv, SV *encoding)
        const char *s;
        dSP;
        ENTER;
+       PUSHSTACK;
        SAVETMPS;
        save_re_context();
        PUSHMARK(sp);
@@ -14100,6 +14101,7 @@ Perl_sv_recode_to_utf8(pTHX_ SV *sv, SV *encoding)
            SvCUR_set(sv, len);
        }
        FREETMPS;
+       POPSTACK;
        LEAVE;
        if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
            /* clear pos and any utf8 cache */