diff --git a/data/tests/empty-desc.icc b/data/tests/empty-desc.icc new file mode 100644 index 00000000..d05ff6d1 Binary files /dev/null and b/data/tests/empty-desc.icc differ diff --git a/data/tests/meson.build b/data/tests/meson.build index 8b38f10e..5630e368 100644 --- a/data/tests/meson.build +++ b/data/tests/meson.build @@ -4,6 +4,7 @@ if get_option('installed_tests') 'corrupt-dict.icc', 'crayons.icc', 'DELL-U2713H.bin', + 'empty-desc.icc', 'empty.icc', 'example.cmf', 'example.sp', diff --git a/lib/colord/cd-icc.c b/lib/colord/cd-icc.c index 7ea5f6e7..b5efee85 100644 --- a/lib/colord/cd-icc.c +++ b/lib/colord/cd-icc.c @@ -2619,8 +2619,13 @@ cd_icc_get_mluc_data (CdIcc *icc, country_code, NULL, 0); - if (text_size == 0) + if (text_size == 0) { + g_set_error_literal (error, + CD_ICC_ERROR, + CD_ICC_ERROR_NO_DATA, + "cmsSigProfile*Tag is empty"); goto out; + } /* load wide chars */ wtext = g_new (gunichar, text_size); @@ -2629,8 +2634,13 @@ cd_icc_get_mluc_data (CdIcc *icc, country_code, (wchar_t *) wtext, text_size); - if (text_size == 0) + if (text_size == 0) { + g_set_error_literal (error, + CD_ICC_ERROR, + CD_ICC_ERROR_NO_DATA, + "cmsSigProfile*Tag is empty"); goto out; + } /* insert UTF-8 value into locale cache */ text_buffer = g_ucs4_to_utf8 (wtext, -1, NULL, NULL, error); diff --git a/lib/colord/cd-test-private.c b/lib/colord/cd-test-private.c index 62d6a6c4..ef51ba78 100644 --- a/lib/colord/cd-test-private.c +++ b/lib/colord/cd-test-private.c @@ -1446,6 +1446,37 @@ colord_icc_clear_func (void) g_object_unref (icc); } +static void +colord_icc_empty_desc_func (void) +{ + CdIcc *icc; + const gchar *tmp; + gboolean ret; + g_autofree gchar *filename = NULL; + g_autoptr(GError) error = NULL; + g_autoptr(GFile) file = NULL; + + /* empty-desc.icc has a 'desc' (mluc) tag whose single en-US record has + * a string length of zero, so lcms parses it as present-but-empty + * (cmsMLUgetWide() returns 0). Regression test: cd_icc_get_description() + * must return NULL *with* a GError set, never NULL with error==NULL -- + * the latter crashed the daemon in cd_main_daemon_method_call() (via + * error->message) when a client loaded the profile with CreateProfile. */ + icc = cd_icc_new (); + filename = cd_test_get_filename ("empty-desc.icc"); + g_assert (filename != NULL); + file = g_file_new_for_path (filename); + ret = cd_icc_load_file (icc, file, CD_ICC_LOAD_FLAGS_NONE, NULL, &error); + g_assert_no_error (error); + g_assert (ret); + + tmp = cd_icc_get_description (icc, NULL, &error); + g_assert_error (error, CD_ICC_ERROR, CD_ICC_ERROR_NO_DATA); + g_assert_cmpstr (tmp, ==, NULL); + + g_object_unref (icc); +} + static void colord_icc_func (void) { @@ -2410,6 +2441,7 @@ main (int argc, char **argv) g_test_add_func ("/colord/icc{characterization}", colord_icc_characterization_func); g_test_add_func ("/colord/icc{save}", colord_icc_save_func); g_test_add_func ("/colord/icc{empty}", colord_icc_empty_func); + g_test_add_func ("/colord/icc{empty-desc}", colord_icc_empty_desc_func); g_test_add_func ("/colord/icc{corrupt-dict}", colord_icc_corrupt_dict_func); g_test_add_func ("/colord/icc{clear}", colord_icc_clear_func); g_test_add_func ("/colord/icc{tags}", colord_icc_tags_func);