This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
RT #127742: Hash keys are limited to 2 GB - throw an exception if hash keys are too...
authorAaron Crane <arc@cpan.org>
Thu, 1 Jun 2017 12:42:22 +0000 (14:42 +0200)
committerYves Orton <demerphq@gmail.com>
Thu, 1 Jun 2017 15:17:34 +0000 (17:17 +0200)
commitb02f36453d1392e2b0bd62fdde2b286fb60bd5bc
tree511763b834e942d731ea762309284dccbd5450d0
parent1cf41740f284a4e05bbefc5b15c5ffd9c254aa78
RT #127742: Hash keys are limited to 2 GB - throw an exception if hash keys are too long

We currently require hash keys to be less than 2**31 bytes long. But (a)
nothing actually tries to enforce that, and (b) if a Perl program tries to
create a hash with such a key (using a 64-bit system), we miscalculate the
size of a memory block, yielding a panic:

$ ./perl -e '+{ "x" x 2**31, undef }'
panic: malloc, size=18446744071562068026 at -e line 1.

Instead, check for this situation, and croak with an appropriate (new)
diagnostic in the unlikely event that it occurs.

This also involves changing the type of an argument to a public API function:
Perl_share_hek() previously took the key's length as an I32, but that makes
it impossible to detect over-long keys, so it must be SSize_t instead.

From Yves:
We also inject the length test into the PERL_HASH() macro, so that where
the macro is used *before* calling into any of the hv functions we can
avoid hashing a very long string only to throw an exception that it is
too long. Might as well fail fast.
MANIFEST
embed.fnc
hv.c
hv_func.h
pod/perldiag.pod
proto.h
t/bigmem/hash.t [new file with mode: 0644]