So I dug into this one and it looks to me like the best approach. Here's a draft patch against 10-stable, if nobody can think of any showstoppers then I'll do the rest of the versions and commit them.
How does this guard against the case when the same OID gets inserted in the toast table again, with matching lengths etc? Rare but seems possible, no?
I think we should look for a more complete solution how hard these bugs are to detect and fix.