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

[perl #118551] Storable hooks silently convert '' to undef

From:
Tony Cook via RT
Date:
August 6, 2019 05:01
Subject:
[perl #118551] Storable hooks silently convert '' to undef
Message ID:
rt-4.0.24-7679-1565067687-1585.118551-15-0@perl.org
On Thu, 20 Jun 2013 09:31:42 -0700, Michael.Jacob3@de.ibm.com wrote:
> If the serialized form returned by STORABLE_freeze() is the empty
> string
> STORABLE_thaw()/_attach() will be fed undef instead.
> 
> (This may be intended but not documented.)
> 
> package xyz;
> 
> use Storable qw(freeze thaw);
> 
> sub new {
>         my $class = shift;
>         my $string = shift;
>         die 'Bad data' unless defined $string;
>         my $self = { string => $string };
>         return bless $self, $class;
> }
> 
> sub STORABLE_freeze {
>         my $self = shift;
>         my $cloning = shift;
>         return if $cloning;
>         return ($self->{string});
> }
> 
> sub STORABLE_attach {
>         my $class = shift;
>         my $cloning = shift;
>         my $string = shift;
>         return $class->new($string);
> }
> 
> print $Storable::VERSION, "\n"; # 2.39
> 
> $a = [ xyz->new('a'), xyz->new('') ];
> 
> $b = freeze($a);
> 
> thaw($b); # <-- dies here with "Bad data"

The fix for this was merged into blead as 48968138d19790da77fff757c57f19594b144e11 and released as part of perl 5.28.0.

Thanks for the report.

Closing.

Tony

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=118551



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About