develooper Front page | perl.perl5.porters | Postings from March 2013

Re: SV_CHECK_THINKFIRST() needs to be rethought and further COW woes....

Thread Previous | Thread Next
March 25, 2013 12:20
Re: SV_CHECK_THINKFIRST() needs to be rethought and further COW woes....
Message ID:
On 25 March 2013 13:13, Dave Mitchell <> wrote:
> On Mon, Mar 25, 2013 at 10:14:18AM +0100, demerphq wrote:
>> To make things worse btw, IMO we have a real issue with COW, in that
>> a) COW strings no longer have the READONLY flag set, code that wants
>> to do an inplace modification based on this flag not being set will
>> silently start modifying COW strings.
>> Lastly, I thought COW was disabled, but I see lots of code related to
>> it. Devel::Peek still reports keys() as being COW, etc.
>> I think we have a real mess on our hands here. I feel really pessimistic.
> My (vague) understanding is that although general COW strings have been
> disabled, the pre-existing  shared hash key mechanism is still there, but
> rather than using the FAKE/READONLY flag combination, it uses the new IsCOW
> flag to indicate the sharedness

Thats my point. With FAKE+READONLY code like HTML::Entities breaks in
an annoying but from the internals point of view harmless way. IOW, it
refuses to corrupt the PV that holds the key.

Now on Perl5.16 the "annoying" part is gone, but as the SV is no
longer READONLY something like HTML::Entities will think it is normal,
and then modify the PV. Assuming modifying the PV doesnt cause a SEGV
something like HTML::Entities will silently corrupt the PL_strtab (the
master hash table) and any hash that mentions that key prior to it
being corrupted. From that point on Perl is in undefined state. The
master string table will contain a HEK that contains a string which
does not match the hash value for the string, and at that point almost
anything could happen.

IOW, FAKE+READONLY still told code "be careful, here be dragons"
whereas "COW" doesn't say this at all.


perl -Mre=debug -e "/just|another|perl|hacker/"

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