Harden Memoization code against broken data types
authorDavid Rowley <[email protected]>
Wed, 8 Jun 2022 00:39:09 +0000 (12:39 +1200)
committerDavid Rowley <[email protected]>
Wed, 8 Jun 2022 00:39:09 +0000 (12:39 +1200)
commitfa5185b26c45afb8407bca2941bec95e0aef862b
tree0c7a742c72ced5e0d8e22537508d0de9b6baf740
parentbf4717b0910763e81ffbf0358de06a88faee5132
Harden Memoization code against broken data types

Bug #17512 highlighted that a suitably broken data type could cause the
backend to crash if either the hash function or equality function were in
someway non-deterministic based on their input values.  Such a data type
could cause a crash of the backend due to some code which assumes that
we'll always find a hash table entry corresponding to an item in the
Memoize LRU list.

Here we remove the assumption that we'll always find the entry
corresponding to the given LRU list item and add run-time checks to verify
we have found the given item in the cache.

This is not a fix for bug #17512, but it will turn the crash reported by
that bug report into an internal ERROR.

Reported-by: Ales Zeleny
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/CAApHDvpxFSTwvoYWT7kmFVSZ9zLAeHb=S9vrz=RExMgSkQNWqw@mail.gmail.com
Backpatch-through: 14, where Memoize was added.
src/backend/executor/nodeMemoize.c