Thanks for writing those patches. The image.c patch is obviously needed to prevent a core dump, so I installed the attached variant of it (added a comment, changed a never-can-happen branch in obsolete code to an eassume). I assume the Elisp changes are good too, but I didn't check them so didn't install them.