Re: BUG #5334: Version 2.22 of Perl Safe module breaks UTF8 PostgreSQL 8.4

From: Tim Bunce <Tim(dot)Bunce(at)pobox(dot)com>
To: Alex Hunsaker <badalex(at)gmail(dot)com>
Cc: Tim Bunce <Tim(dot)Bunce(at)pobox(dot)com>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5334: Version 2.22 of Perl Safe module breaks UTF8 PostgreSQL 8.4
Date: 2010-02-19 13:06:17
Message-ID: 20100219130617.GG373@timac.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I've got the patch to Safe ready but the more I think about it the more
I think the right fix is for Safe to automatically fully load utf8.pm
(and utf8_heavy.pl) and to always share SWASHNEW itself.

Assuming perl5-porters agree then the next release of Safe will do that
ad this patch won't be needed. (Other than it possibly being worthwhile
to detect the 'bad' versions of Safe.)

Tim.

On Fri, Feb 19, 2010 at 09:30:41AM +0000, Tim Bunce wrote:
> On Thu, Feb 18, 2010 at 11:32:38AM -0700, Alex Hunsaker wrote:
> > On Thu, Feb 18, 2010 at 11:09, Tim Bunce <Tim(dot)Bunce(at)pobox(dot)com> wrote:
> > > The key line is:
> > >
> > >    *PLPerl::utf8::SWASHNEW = \&utf8::SWASHNEW;
> >
> > Hrm... It seems to work for me in HEAD and AFAICS we dont have that
> > line. Did I just miss it? Or did you happen to fix it in another way
> > with your refactoring?
>
> To be honest I'm not sure. I plan to look into that today.
>
> > Another Idea that comes to mind would be instead of (in ::mksafefunc):
> > my $subref = ->reval(sub {} );
> > $subref->();
> >
> > do:
> > my $subref = ->reval(sub {});
> > return sub { ->reval("$subreb->();"); }
> >
> > or something...
> >
> > I did a few quick tests but it failed miserably for me... Im also not
> > fond of adding yet another closure. :)
>
> No amount of closure wrapping will fix the problem.
>
> > > This allows the perl regex logic to call the SWASHNEW method that's
> > > called when information from the Unicode character database is needed.
> > > (The lack of that method was causing the regex logic to think that the
> > > utf8 module wasn't loaded, so it would try to 'require' it but fail due
> > > to the restrictions of the Safe compartment.)
> >
> > Makes me think we might just be able to share some of utf8 package in the safe?
>
> I tried. The perl utf8.c code does a method lookup of SWASHNEW to decide
> if the utf8 module has been loaded. So if SWASHNEW is shared _before_
> utf8 is loaded *and used* then the method lookup works (it finds the
> shared stub) and the utf8 module never gets loaded.
>
> (The *and used* complication is due to utf8.pm being a thin wrapper with
> an AUTOLOAD trampoline that loads utf8_heavy.pl on first use. More fun.)
>
> I do have a patch for Safe that, if utf8 is loaded, will ensure it's
> 'used' and then auto-share SWASHNEW. That won't fix PostgreSQL 8.x
> though because utf8 isn't loaded at the time Safe->new is called.
>
> > > The rest of the patch is updates the surrounding code to the same
> > > simplified 'utf8fix' logic used in PostgreSQL 9.0, and the same Safe
> > > version checks.
> >
> > From a quick look it looks ok.
>
> Thanks.
>
> Tim.
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alex Hunsaker 2010-02-19 16:18:01 Re: BUG #5334: Version 2.22 of Perl Safe module breaks UTF8 PostgreSQL 8.4
Previous Message Tim Bunce 2010-02-19 09:30:41 Re: BUG #5334: Version 2.22 of Perl Safe module breaks UTF8 PostgreSQL 8.4