Thanks Ling-Xiao Yang for the report and test, and Preston Timmons for the fix. Backport of e643ba8bcf from master
e643ba8bcf