Skip to content

Add protection against corrupted embedded ICC profile #18977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/iop/colorin.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of darktable,
Copyright (C) 2009-2024 darktable developers.
Copyright (C) 2009-2025 darktable developers.

darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1810,6 +1810,8 @@ void reload_defaults(dt_iop_module_t *self)

if(g)
{
gboolean profile_embedded_but_corrupted = FALSE;

char *tooltip_part_profile_dirs =
dt_ioppr_get_location_tooltip("in", _("external ICC profiles"));

Expand All @@ -1819,6 +1821,17 @@ void reload_defaults(dt_iop_module_t *self)
{
cmsHPROFILE cmsprofile = cmsOpenProfileFromMem(img->profile, img->profile_size);

// So, exiv2 read the embedded ICC profile from the image file, but it
// can be corrupted to the point that lcms2 cannot open it as a profile.
// In such a case, we have to bail out of the profile reading code, as
// we cannot read the profile properties and change the tooltip.
if(!cmsprofile)
{
profile_embedded_but_corrupted = TRUE;
dt_print(DT_DEBUG_ALWAYS, "[colorin] ICC profile is embedded but corrupted");
goto corrupted_profile;
}

char iccDesc[64]; iccDesc[0] = '\0';
cmsGetProfileInfoASCII(cmsprofile, cmsInfoDescription, "en", "US", iccDesc, 64);
char iccManuf[64]; iccManuf[0] = '\0';
Expand Down Expand Up @@ -1876,10 +1889,12 @@ void reload_defaults(dt_iop_module_t *self)
if(bufsize)
free(iccCopyr);
}
else

// Make a generic tooltip if there is no ICC profile in the current image,
// or we jumped here because profile is corrupted.
corrupted_profile:
if((color_profile != DT_COLORSPACE_EMBEDDED_ICC) || profile_embedded_but_corrupted)
{
// If the current image does not have an embedded profile, let's
// display a generic tooltip
gtk_widget_set_tooltip_markup(g->profile_combobox, tooltip_part_profile_dirs);
g_free(tooltip_part_profile_dirs);
}
Expand Down
Loading