Live data from Hacker News

Hardening Perl's Hash Function

blog.booking.com

11–14 of 14 posts

Re: Hardening Perl's Hash Function

#11

> An attacker could precalculate one or more suffixes such that H(x) == H( concat(x, suffix) ) which would then allow an attacker to trivially construct an infinite set of keys which would always collide into the same bucket. We hardened the hash by mixing in the length of the key into the seed. This prevents making an infinite set of keys that collide, yes, but does not fix the problem completely. It only increases…

> But if I was looking for guarantees for worst-case performance, I'd (pretty much) never use a HashMap. I wonder why none[1] of the major dynamic languages offer the option of running with the built-in associative-data structures implemented using a Red-Black Tree. Seems like an obvious thing to do. There are interface issues, of course. In particular, for a new type to be usable as a key, it would need to provide a…

I reckon because pointer-based trees are very slow compared to array-based data structures; these are constant factors due to memory accesses so they have nothing to do with the average and worst case performance you mention. For databases b-trees are appropriate, but for most uses of associative data structures hash tables are just very hard to beat.

Re: Hardening Perl's Hash Function

#12
post #10
post #9

Earlier quoted context omitted.

> Wait, does that mean that iterating across the members of a Lua table is not in deterministic order? Yes. And it is documented as such. Any dependency on repeatable iteration order is a bug.

Huh. I'm not involved directly in SpringRTS, but I'm going to take a look at the code... I assume there's a compilation flag for Lua to disable that, or they've hacked it up and are using a custom interpreter, because protecting sync is paramount.

Just using "sort(hash-keys())" instead of "hash-keys()" should be a trivial patch that fixes this.

Re: Hardening Perl's Hash Function

#13

Thats why I like Lua's hash implementation that adds a random seed to the hashing algorithm to limit those pathological side effects...

That's often insufficient. For MurmurHash{2,3}, for example, you can generate arbitrarily many keys that collide regardless of the random seed. Code is on the SipHash page:

https://131002.net/siphash/

Re: Hardening Perl's Hash Function

#14

Earlier quoted context omitted.

> But if I was looking for guarantees for worst-case performance, I'd (pretty much) never use a HashMap. I wonder why none[1] of the major dynamic languages offer the option of running with the built-in associative-data structures implemented using a Red-Black Tree. Seems like an obvious thing to do. There are interface issues, of course. In particular, for a new type to be usable as a key, it would need to provide a…

> I wonder why none[1] of the major dynamic languages offer the option of running with the built-in associative-data structures implemented using a Red-Black Tree. Seems like an obvious thing to do. It's not a command-line option, but Perl lets you "tie" a hash to a different backing implementation, and there are some tree-based ones: use Tree::RB; tie my %hash, 'Tree::RB';

Wow, I had no idea. That's a nice feature.
Post reply on HN