develooper Front page | perl.perl5.porters | Postings from September 2019

Re: [perl #134409] Perl intepreter exception on expressionsubstitution

Thread Previous
Dave Mitchell
September 14, 2019 15:37
Re: [perl #134409] Perl intepreter exception on expressionsubstitution
Message ID:
On Thu, Sep 12, 2019 at 11:07:13AM +0100, Dave Mitchell wrote:
> On Mon, Sep 09, 2019 at 08:37:48PM +0000, Chris Crook wrote:
> > Good news - the loop is only hit once or twice before it errors
> > (depending on the order of retrieval from hash).  I put a bit more code
> > in ... results below.
> More good news: with the help of the extra feedback, I've managed to
> construct a short script which fails on bleadperl. I'm looking into it
> now.

Now fixed in blead with the following commit:

commit 4a69216a74159df74779841fa79d731bcc5c6a9d
Author:     David Mitchell <>
AuthorDate: Sat Sep 14 16:18:46 2019 +0100
Commit:     David Mitchell <>
CommitDate: Sat Sep 14 16:18:46 2019 +0100

    Avoid panic when last s///g is tainted and utf8
    RT #134409
    In a repeated substitution, where the replacement is an expression,
    and when the last replacement value is both tainted and utf8, and
    everything earlier has been plain, and the final string is suitably
    shorter than the original, a panic resulted:
        sv_pos_b2u: bad byte offset, blen=1, byte=6
    This is because when at the end, taint magic is being being added to
    the target of the s///, the target SV has already had its buffer updated
    with the shorter result string, but still has the pos() magic set which
    corresponded to the original longer string (this pos value would, in the
    normal flow of things, be reset shortly afterwards).
    One quirk of sv_magic(), which adds any sort of magic including taint
    magic, is that it always checks for the presence of pos() magic, and if
    so, converts the byte to utf8 offset if necessary. This was seeing the
    invalid pos() offset and panicing.
    The check was added by v5.19.3-111-g25fdce4a16:
        "Stop pos() from being confused by changing utf8ness"
    It seems like a bit of hack to recalibrate pos() each time sv_magic()
    is called, but I've left that alone (sleeping dogs and all that) and
    instead added a hack in the taint code path in pp_substcont to reset pos
    before setting taint.

Spock (or Data) is fired from his high-ranking position for not being able
to understand the most basic nuances of about one in three sentences that
anyone says to him.
    -- Things That Never Happen in "Star Trek" #19

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About