|P is for Practical|
hash randomization and keys()by dug (Chaplain)
|on Jul 29, 2007 at 19:28 UTC ( #629429=perlquestion: print w/replies, xml )||Need Help??|
dug has asked for the wisdom of the Perl Monks concerning the following question:
At $work a co-worker recently sent an obfu out to the tech list that relied on keys() returning the keys of a hash in the same order every time the piece of code was executed. My perl is 5.8.8, compiled without "-DUSE_HASH_SEED_EXPLICIT", and I don't have the "PERL_HASH_SEED" environment variable set.
Given my interpretation of `perldoc -f keys`, and `perldoc perlrun`, every time I call keys() on a hash, even between runs of perl, I will get a different order. This is the relevant piece of documentation from `perldoc -f keys`:
Since Perl 5.8.1 the ordering is different even between different runs of Perl for security reasons (see "Algorithmic Complexity Attacks" in perlsec).
But when I run:
"ACE" is printed every time (at least every time that I've run it).
Is there a bug in the way I'm reading the documentation? If I remember correctly (which is unlikely), this was kind of a big deal when 5.8.1 came out, as there was a fair bit of code in the wild that disobeyed the documentation and relied on hash ordering.
My understanding of the current implementation given my version, compilation options and environment variables was that I could rely on hashes *not* being ordered the same between runs of perl. I'm clearly missing something. Can anyone shed some light?
Thanks,-- Douglas Hunter
Back to Seekers of Perl Wisdom