Backport of 3826aed46d7d4310c2ab6777a4f92165ca4d8d4f from master
This was a regression introduced by 7deeabc7c7526786df6894429ce89a9c4b614086 to address CVE-2019-14234. Thanks Tim Kleinschmidt for the report and Mariusz for the tests. Backport of 6c3dfba89215fc56fc27ef61829a6fff88be4abb from master
Backport of bd7e0f81f8590eadcb820c976ba03c9b75bbcad6 from master