Upstream fix from https://bitbucket.org/libgd/gd-libgd/issue/75