Skip to content

Instantly share code, notes, and snippets.

@adsr
Created February 6, 2025 22:10
Show Gist options
  • Save adsr/9d70177b255e9d41011c20c09f32780c to your computer and use it in GitHub Desktop.
Save adsr/9d70177b255e9d41011c20c09f32780c to your computer and use it in GitHub Desktop.
diff --git a/gmagick.c b/gmagick.c
index 5102a42..f86ac2f 100644
--- a/gmagick.c
+++ b/gmagick.c
@@ -258,22 +258,23 @@ static void php_gmagick_init_globals(zend_gmagick_globals *gmagick_globals)
// 10 is magick number, that seems to be enough.
gmagick_globals->shutdown_sleep_count = 10;
}
/* {{{ PHP_MINIT_FUNCTION(gmagick)
*/
PHP_MINIT_FUNCTION(gmagick)
{
char *cwd;
size_t cwd_len;
-
zend_class_entry ce;
+ ExceptionInfo exception_info;
+ ExceptionType exception_type;
ZEND_INIT_MODULE_GLOBALS(gmagick, php_gmagick_init_globals, NULL);
/* Exception */
INIT_CLASS_ENTRY(ce, "GmagickException", NULL);
php_gmagick_exception_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default());
php_gmagick_exception_class_entry->ce_flags |= ZEND_ACC_FINAL;
INIT_CLASS_ENTRY(ce, "GmagickPixelException", NULL);
php_gmagickpixel_exception_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default());
@@ -303,24 +304,30 @@ PHP_MINIT_FUNCTION(gmagick)
gmagickpixel_object_handlers.offset = XtOffsetOf(php_gmagickpixel_object, zo);
gmagickpixel_object_handlers.free_obj = php_gmagickpixel_object_free_storage;
gmagickpixel_object_handlers.clone_obj = php_gmagick_clone_gmagickpixel_object;
/* Initialize GraphicsMagick environment */
cwd = virtual_getcwd_ex(&cwd_len);
if (!cwd)
return FAILURE;
+ GetExceptionInfo(&exception_info);
+ InitializeMagickEx(cwd, MAGICK_OPT_NO_SIGNAL_HANDER, &exception_info);
+ exception_type = exception_info.severity;
+ DestroyExceptionInfo(&exception_info);
- InitializeMagick(cwd);
efree(cwd);
+ if (exception_type != UndefinedException)
+ return FAILURE;
+
/* init constants */
php_gmagick_initialize_constants();
REGISTER_INI_ENTRIES();
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION(gmagick)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment