I created a pull request that appears to fix this, however since the change replaces 10 lines of code with a single line of code, I would recommend checking it thoroughly before merging it.
EDIT: The patch currently causes a separate crash, so should not yet be merged.
EDIT 2: I believe that crash has now been fixed.