Mailing List Archive

panic: sv_setpvn called with negative strlen
When previewing stories today, we started seeing the following errors:

panic: sv_setpvn called with negative strlen at
/usr/local/bricolage/lib/Bric/Util/Burner/Mason.pm line 590
panic: sv_setpvn called with negative strlen at
/usr/local/bricolage/lib/Bric/Util/Burner/Mason.pm line 594

I finally determined that a single story was causing the problem.
Basically, when this story is previewed, it causes the above error and
then most previews for other stories afterward cause the same error.
However, when I restart Bricolage, the problem went away until I
previewed the problem story again.

This story outputs a PHP file and this line of code seems to be the
cause:

$uri = urlencode(preg_replace('/&?(x|y)=\d*/', '',
$_SERVER['REQUEST_URI']));

I changed the code to the following and the error went away:

$uri = preg_replace('/&?(x)=\d*/', '', $_SERVER['REQUEST_URI']);
$uri = urlencode(preg_replace('/&?(y)=\d*/', '', $uri));

Here's the relevant code from Mason.pm (1.10.3):

sub end_page {
my $self = shift;

my ($page, $buf) = $self->_get(qw(page _buf));
my $file = $self->page_filepath(++$page);
my $uri = $self->page_uri($page);

# Save the page we've created so far.
open(OUT, ">$file") // *** line 590 ***
or throw_gen error => "Unable to open '$file' for writing",
payload => $!;
binmode(OUT, ':' . $self->get_encoding || 'utf8') if ENCODE_OK;
print OUT $$buf; // *** line 594 ***
close(OUT);

# Add a resource to the job object.
$self->add_resource($file, $uri);

# Clear the output buffer.
$$buf = '';
# Increment the page number
$self->_set(['page'], [$page]);
}

It seems odd that story content would cause this sort of problem.

Chris

--------------------------------

Chris Schults
Web Developer
PCC Natural Markets
206-547-1222 x104
chris.schults@pccsea.com
http://www.pccnaturalmarkets.com

Sign up for PCC Fresh, a monthly newsletter filled with seasonal
recipes, exciting new products, and more:
http://www.pccnaturalmarkets.com/enews
Re: panic: sv_setpvn called with negative strlen [ In reply to ]
Can you send the complete template that exhibits the problem? Sounds like a Mason bug.

Thanks,

David

On Jan 7, 2010, at 12:47 PM, Schults, Chris wrote:

> When previewing stories today, we started seeing the following errors:
>
> panic: sv_setpvn called with negative strlen at
> /usr/local/bricolage/lib/Bric/Util/Burner/Mason.pm line 590
> panic: sv_setpvn called with negative strlen at
> /usr/local/bricolage/lib/Bric/Util/Burner/Mason.pm line 594
>
> I finally determined that a single story was causing the problem.
> Basically, when this story is previewed, it causes the above error and
> then most previews for other stories afterward cause the same error.
> However, when I restart Bricolage, the problem went away until I
> previewed the problem story again.
>
> This story outputs a PHP file and this line of code seems to be the
> cause:
>
> $uri = urlencode(preg_replace('/&?(x|y)=\d*/', '',
> $_SERVER['REQUEST_URI']));
>
> I changed the code to the following and the error went away:
>
> $uri = preg_replace('/&?(x)=\d*/', '', $_SERVER['REQUEST_URI']);
> $uri = urlencode(preg_replace('/&?(y)=\d*/', '', $uri));
>
> Here's the relevant code from Mason.pm (1.10.3):
>
> sub end_page {
> my $self = shift;
>
> my ($page, $buf) = $self->_get(qw(page _buf));
> my $file = $self->page_filepath(++$page);
> my $uri = $self->page_uri($page);
>
> # Save the page we've created so far.
> open(OUT, ">$file") // *** line 590 ***
> or throw_gen error => "Unable to open '$file' for writing",
> payload => $!;
> binmode(OUT, ':' . $self->get_encoding || 'utf8') if ENCODE_OK;
> print OUT $$buf; // *** line 594 ***
> close(OUT);
>
> # Add a resource to the job object.
> $self->add_resource($file, $uri);
>
> # Clear the output buffer.
> $$buf = '';
> # Increment the page number
> $self->_set(['page'], [$page]);
> }
>
> It seems odd that story content would cause this sort of problem.
>
> Chris
>
> --------------------------------
>
> Chris Schults
> Web Developer
> PCC Natural Markets
> 206-547-1222 x104
> chris.schults@pccsea.com
> http://www.pccnaturalmarkets.com
>
> Sign up for PCC Fresh, a monthly newsletter filled with seasonal
> recipes, exciting new products, and more:
> http://www.pccnaturalmarkets.com/enews
>
>
>
RE: panic: sv_setpvn called with negative strlen [ In reply to ]
> Can you send the complete template that exhibits the problem? Sounds
> like a Mason bug.

For this type of story, the template is a one liner:

% print $element->get_value('code');

In this case, the offending line of PHP code was:

$uri = urlencode(preg_replace('/&?(x|y)=\d*/', '',
$_SERVER['REQUEST_URI']));

Again, we're still using version 1.10.3.

Chris
Re: panic: sv_setpvn called with negative strlen [ In reply to ]
On Jan 7, 2010, at 2:50 PM, Schults, Chris wrote:

>> Can you send the complete template that exhibits the problem? Sounds
>> like a Mason bug.
>
> For this type of story, the template is a one liner:
>
> % print $element->get_value('code');
>
> In this case, the offending line of PHP code was:
>
> $uri = urlencode(preg_replace('/&?(x|y)=\d*/', '',
> $_SERVER['REQUEST_URI']));
>
> Again, we're still using version 1.10.3.

I dont' follow why PHP code even comes into the equation. It's just output by Mason somewhere, right? Is that what's stored in the "code" field?

Best,

David
Re: panic: sv_setpvn called with negative strlen [ In reply to ]
Hi,

> On Jan 7, 2010, at 12:47 PM, Schults, Chris wrote:
>
> > When previewing stories today, we started seeing the following errors:
> >
> > panic: sv_setpvn called with negative strlen at
> > /usr/local/bricolage/lib/Bric/Util/Burner/Mason.pm line 590
> > panic: sv_setpvn called with negative strlen at
> > /usr/local/bricolage/lib/Bric/Util/Burner/Mason.pm line 594

Could be a Perl bug:

http://www.gossamer-threads.com/lists/engine?list=perl&do=search_results&search_forum=forum_1&search_string=panic+sv_setpvn+negative&search_type=AND

Might be an encoding issue and changing the template changed the
encoding.

What version of perl are you using (output of perl -V).

Cheers,

Alex

--
Alex Krohn <alex@gossamer-threads.com>
RE: panic: sv_setpvn called with negative strlen [ In reply to ]
> Could be a Perl bug:
>
> http://www.gossamer-
>
threads.com/lists/engine?list=perl&do=search_results&search_forum=forum
> _1&search_string=panic+sv_setpvn+negative&search_type=AND
>
> Might be an encoding issue and changing the template changed the
> encoding.
>
> What version of perl are you using (output of perl -V).

Alex, perl5 (revision 5 version 8 subversion 8).

Ok, here is the strange thing, I just restored my original code, and I
haven't been able to reproduce the error yet. And what I hadn't
mentioned previously, was that this code was in place for at least a few
days with no problems.

Interesting you mention encoding as my autohandler does some encoding:
$burner->set_encoding('encoding(iso-8859-1)');

Chris
Re: panic: sv_setpvn called with negative strlen [ In reply to ]
Hi Chris,

> Alex, perl5 (revision 5 version 8 subversion 8).
>
> Ok, here is the strange thing, I just restored my original code, and I
> haven't been able to reproduce the error yet. And what I hadn't
> mentioned previously, was that this code was in place for at least a few
> days with no problems.
>
> Interesting you mention encoding as my autohandler does some encoding:
> $burner->set_encoding('encoding(iso-8859-1)');

Without something minimal to reproduce it, it's going to be
difficult/impossible to track down. Most likely the original code was
entered in a different encoding (utf8?) and you are hitting an obscure
perl bug.

Cheers,

Alex

--
Alex Krohn <alex@gossamer-threads.com>
Re: panic: sv_setpvn called with negative strlen [ In reply to ]
On Jan 7, 2010, at 6:03 PM, Alex Krohn wrote:

> Without something minimal to reproduce it, it's going to be
> difficult/impossible to track down. Most likely the original code was
> entered in a different encoding (utf8?) and you are hitting an obscure
> perl bug.

All Bricolage text data is stored in UTF-8. You can't put anything else in it because PostgreSQL will reject it. This line:

$burner->set_encoding('encoding(iso-8859-1)');

Tells the burner to convert the data to Latin-1 before writing out the files to be distributed to the Web server. Should all be fine.

Best,

David