Applied upstream patch to fix a bug