Fix several vulnerabilities allowing heap overwrite, read violations and a function pointer overwrite. From: Moritz Grimm