I am trying to trigger the hash randomization feature in Perl 5.8.2 and later. To do this, I need a set of keys that would be pathological but for the randomization feature. I tried using MJD's code, but that didn’t work. And, now that I look at it, I shouldn’t be surprised. It comes from 1997, and we have switched hashing functions since then.
Does anyone know of a set of pathological keys, or how to generate them? I guess I should just go look at the hash function and reverse engineer a solution, but I am lazy.
Note: this information is valid for perl between 5.8.2 and 5.17.x. Beginning with perl 5.18, perl uses a new hash algorithm, hash randomization occurs on every startup (instead of only when a pathological hash is detected), and
PERL_HASH_SEEDis interpreted differently. As perl now uses a 128-bit hash seed, the “pathological hash” condition should be almost impossible to trigger intentionally.Original answer: If you force the hash seed to 0 by putting
PERL_HASH_SEED=0in the environment before perl starts, the collection of keys"\0","\0\0","\0\0\0", etc. will cause every key to land in hash bucket 0 with current perls.