SKS-Keyserver / sks-keyserver

OpenPGP keyserver
GNU General Public License v2.0
135 stars 15 forks source link

Make the key parsing functions in keyMerge tail-recursive. #78

Closed wiml closed 4 years ago

wiml commented 4 years ago

When importing a current keydump, SKS will crash (on my machine at least) due to too-deep recursion in siglist. This is just because there are some keys with a ridiculous number of signatures (due to vandalism/attacks, but still). Presumably any other operation that requires merging into that key will also cause the same problem, but this is the situation I found first and was easy to reproduce.

This patch makes the key parsing routines tail-recursive by adding an unfold-like helper function. With this change SKS can import a keydump without requiring a huge stack.

Presumably this change causes the allocation of a few extra cells of short-lived garbage in the key merge operation, but in testing I wasn't able to detect a performance difference (using 4.10.0+flambda).

ygrek commented 4 years ago

I wonder if this is the reason I had to use LimitSTACK=infinity for db server..

ygrek commented 4 years ago

funny enough, I cannot reproduce stack overflow in parse_keystr because I am seeing stack overflow in key_to_stream first :)

ygrek commented 4 years ago

cherry picked in c753283, thanks!