While here, backport critical security and compatibility fixes from upstream PR: 246106 Security: CVE-2018-20540