Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Storable CPAN distribution.

Report information
The Basics
Id: 33242
Status: resolved
Priority: 0/
Queue: Storable

People
Owner: ams [...] wiw.org
Requestors: ianburrell [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 2.18
Fixed in: (no value)



Subject: Segfault when restoring blessed reference to overloaded object
Storable is segfaulting when restoring a serialized blessed reference to overloaded object. This happens with a blessed reference to a DateTime object. This happens on Perl 5.8 and Storable 2.18. On Perl 5.10, it prints the following message: sv_upgrade from type 8 down to type 4 at ../../lib/Storable.pm (autosplit into ../../lib/auto/Storable/thaw.al) line 415, at overload.pl line 6 I have attached a script which produces the problem.
Subject: overload.pl
#!/usr/local/bin/perl58 use Storable qw/ freeze thaw /; my $bar = Bar->new(); thaw(freeze($bar)); package Bar; sub new { return bless \Foo->new(), 'Bar'; } package Foo; use overload '-' => \&mysub; sub new { return bless {}, 'Foo' } sub mysub { return 1; }
From: ianburrell [...] gmail.com
Here is a patch to t/overload.t which adds a test which shows the problem.
--- t/overload.t.orig 2008-02-14 14:14:07.000000000 -0800 +++ t/overload.t 2008-02-14 14:12:33.000000000 -0800 @@ -25,7 +25,7 @@ use Storable qw(freeze thaw); -print "1..16\n"; +print "1..20\n"; package OVERLOADED; @@ -103,4 +103,39 @@ ok 14, ref ($t) eq 'REF'; ok 15, ref ($$t) eq 'HAS_OVERLOAD'; ok 16, $$$t eq 'snow'; + +package OVER2; + +use overload + '+' => \&plus, + '""' => sub { ref $_[0] }; + +sub plus { + return 314; +} + +sub make { + my $self = bless {}, shift; + return $self; +} + +package REF_OF_OVER; + +sub make { + my $over = OVER2->make(); + my $self = bless \$over, shift; + return $self; +} + + +package main; + +$a = REF_OF_OVER->make(); +$b = thaw freeze $a; + +ok 17, ref $b eq 'REF_OF_OVER'; +ok 18, $$a + $$a == 314; +ok 19, ref $$b eq 'OVER2'; +ok 20, $$b + $$b == 314; + 1;
From: ianburrell [...] gmail.com
Here is a patch that fixes the bug. It includes a different (and simpler) test for the problem.
Index: Storable-2.18/Storable.xs --- Storable-2.18/Storable.xs 2008-02-14 14:32:05.000000000 -0800 +++ Storable-2.18/Storable.xs 2008-02-14 14:43:00.000000000 -0800 @@ -4561,7 +4561,12 @@ * WARNING: breaks RV encapsulation. */ - sv_upgrade(rv, SVt_RV); + if (cname) { + /* No need to do anything, as rv will already be PVMG. */ + assert (SvTYPE(rv) >= SVt_RV); + } else { + sv_upgrade(rv, SVt_RV); + } SvRV_set(rv, sv); /* $rv = \$sv */ SvROK_on(rv); Index: Storable-2.18/t/overload.t --- Storable-2.18/t/overload.t 2008-02-14 14:26:10.000000000 -0800 +++ Storable-2.18/t/overload.t 2008-02-14 14:41:26.000000000 -0800 @@ -25,7 +25,7 @@ use Storable qw(freeze thaw); -print "1..16\n"; +print "1..20\n"; package OVERLOADED; @@ -59,6 +59,14 @@ return $self; } +package SCALAR_REF_TO_OVER; + +sub create { + my ($class) = @_; + my $over = bless {}, 'OVER'; + return bless \$over, $class; +} + package OVER; use overload @@ -103,4 +111,13 @@ ok 14, ref ($t) eq 'REF'; ok 15, ref ($$t) eq 'HAS_OVERLOAD'; ok 16, $$$t eq 'snow'; + +$c = SCALAR_REF_TO_OVER->create(); +# Don't segfault here +$d = thaw freeze $c; +ok 17, ref($c) eq 'SCALAR_REF_TO_OVER'; +ok 18, ref($d) eq 'SCALAR_REF_TO_OVER'; +ok 19, ref($$c) eq 'OVER'; +ok 20, ref($$d) eq 'OVER'; + 1;
From: skasal [...] redhat.com
Fixed in the recently releases Storable-2.21. Could you please close this ticket?
From: skasal [...] redhat.com
Show quoted text
> Fixed in the recently releases Storable-2.21.
I should have said that though the fix is not identical, I have verified that the patched overload.t attached to this ticket does pass with Storable 2.21.
Fixed in 2.21, as reported by Stepan Kasal.