cperl icon indicating copy to clipboard operation
cperl copied to clipboard

Storable: restricted Storable hashes broken with PERL_PERTURB_KEYS_TOP

Open rurban opened this issue 9 years ago • 0 comments

The restricted flag seems to be gone after some splits, but does reappear. Not repro with cperl proper hashes. Storable does it's own hash creation. The failing test regression came with [perl #73972] http://rt.perl.org/Public/Bug/Display.html?id=73972 It describes exactly the same issue.

Fixed in perl5 with commit 11b24ae76382137a580b9b75114adee14ec7afd2 Author: Jesse Luehrs [email protected] Date: Tue Jun 26 16:47:51 2012 -0500

fix off-by-one when restoring hashes [perl #73972]

Storable tries to preallocate enough space for all of the elements it's
going to receive, both for efficiency reasons and because reallocation
triggers throwing away all of the placeholders in the hash (which are
used for restricted hashes) if the hash isn't already READONLY, and
since Storable rebuilds restricted hashes by first populating all of the
placeholders and then setting it READONLY at the end, this would break
things.

Unfortunately, it was allocating just slightly less than enough space -
hashes reallocate when they hit their limit, not when they exceed it,
and so if you tried to store a restricted hash with a number of keys
right on the boundary, it would trigger a reallocation and lose all of
the allowed keys that it had just stored. This fixes the issue by
allocating the correct amount of space to ensure that reallocation
doesn't happen.

I don't consider that a blocking bug.

rurban avatar Mar 24 '16 16:03 rurban