From: Chip Salzenberg Date: Thu, 29 Oct 2009 00:08:05 +0000 (-0700) Subject: avoid infinite chain of utf8 magic X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f89a570b1f4dda1c19dab17cb7eb6914cdc0717c;p=p5sagit%2Fp5-mst-13.2.git avoid infinite chain of utf8 magic --- diff --git a/sv.c b/sv.c index 811d8ce..5162d2e 100644 --- a/sv.c +++ b/sv.c @@ -6016,7 +6016,8 @@ Perl_sv_len_utf8(pTHX_ register SV *const sv) else { ulen = Perl_utf8_length(aTHX_ s, s + len); if (!SvREADONLY(sv)) { - if (!mg) { + if (!mg && (SvTYPE(sv) < SVt_PVMG || + !(mg = mg_find(sv, PERL_MAGIC_utf8)))) { mg = sv_magicext(sv, 0, PERL_MAGIC_utf8, &PL_vtbl_utf8, 0, 0); } @@ -6096,8 +6097,10 @@ S_sv_pos_u2b_cached(pTHX_ SV *const sv, MAGIC **const mgp, const U8 *const start assert (uoffset >= uoffset0); - if (SvMAGICAL(sv) && !SvREADONLY(sv) && PL_utf8cache - && (*mgp || (*mgp = mg_find(sv, PERL_MAGIC_utf8)))) { + if (!SvREADONLY(sv) + && PL_utf8cache + && (*mgp || (SvTYPE(sv) >= SVt_PVMG && + (*mgp = mg_find(sv, PERL_MAGIC_utf8))))) { if ((*mgp)->mg_ptr) { STRLEN *cache = (STRLEN *) (*mgp)->mg_ptr; if (cache[0] == uoffset) { @@ -6280,7 +6283,8 @@ S_utf8_mg_pos_cache_update(pTHX_ SV *const sv, MAGIC **const mgp, const STRLEN b if (SvREADONLY(sv)) return; - if (!*mgp) { + if (!*mgp && (SvTYPE(sv) < SVt_PVMG || + !(*mgp = mg_find(sv, PERL_MAGIC_utf8)))) { *mgp = sv_magicext(sv, 0, PERL_MAGIC_utf8, (MGVTBL*)&PL_vtbl_utf8, 0, 0); (*mgp)->mg_len = -1; @@ -6477,8 +6481,11 @@ Perl_sv_pos_b2u(pTHX_ register SV *const sv, I32 *const offsetp) send = s + byte; - if (SvMAGICAL(sv) && !SvREADONLY(sv) && PL_utf8cache - && (mg = mg_find(sv, PERL_MAGIC_utf8))) { + if (!SvREADONLY(sv) + && PL_utf8cache + && SvTYPE(sv) >= SVt_PVMG + && (mg = mg_find(sv, PERL_MAGIC_utf8))) + { if (mg->mg_ptr) { STRLEN * const cache = (STRLEN *) mg->mg_ptr; if (cache[1] == byte) {