TESTFUNC_TYPE LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { qcms_enable_iccv4(); qcms_profile* profile = qcms_profile_from_memory(data, size); if (!profile) { return 0; } qcms_profile* srgb_profile = qcms_profile_sRGB(); if (!srgb_profile) { qcms_profile_release(profile); return 0; } transform(profile, srgb_profile, size); // Firefox only checks the display (destination) profile. if (qcms_profile_is_bogus(profile)) { goto release_profiles; }; transform(srgb_profile, profile, size); release_profiles: qcms_profile_release(profile); qcms_profile_release(srgb_profile); return 0; }
// ----------------------------------------------------------------------------- // Color profile handling static int ApplyColorProfile(const WebPData* const profile, WebPDecBuffer* const rgba) { #ifdef WEBP_HAVE_QCMS int i, ok = 0; uint8_t* line; uint8_t major_revision; qcms_profile* input_profile = NULL; qcms_profile* output_profile = NULL; qcms_transform* transform = NULL; const qcms_data_type input_type = QCMS_DATA_RGBA_8; const qcms_data_type output_type = QCMS_DATA_RGBA_8; const qcms_intent intent = QCMS_INTENT_DEFAULT; if (profile == NULL || rgba == NULL) return 0; if (profile->bytes == NULL || profile->size < 10) return 1; major_revision = profile->bytes[8]; qcms_enable_iccv4(); input_profile = qcms_profile_from_memory(profile->bytes, profile->size); // qcms_profile_is_bogus() is broken with ICCv4. if (input_profile == NULL || (major_revision < 4 && qcms_profile_is_bogus(input_profile))) { fprintf(stderr, "Color profile is bogus!\n"); goto Error; } output_profile = qcms_profile_sRGB(); if (output_profile == NULL) { fprintf(stderr, "Error creating output color profile!\n"); goto Error; } qcms_profile_precache_output_transform(output_profile); transform = qcms_transform_create(input_profile, input_type, output_profile, output_type, intent); if (transform == NULL) { fprintf(stderr, "Error creating color transform!\n"); goto Error; } line = rgba->u.RGBA.rgba; for (i = 0; i < rgba->height; ++i, line += rgba->u.RGBA.stride) { qcms_transform_data(transform, line, line, rgba->width); } ok = 1; Error: if (input_profile != NULL) qcms_profile_release(input_profile); if (output_profile != NULL) qcms_profile_release(output_profile); if (transform != NULL) qcms_transform_release(transform); return ok; #else (void)profile; (void)rgba; return 1; #endif // WEBP_HAVE_QCMS }
qcms_profile * gfxPlatform::GetCMSOutputProfile() { if (!gCMSOutputProfile) { NS_TIME_FUNCTION; nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); if (prefs) { nsresult rv; /* Determine if we're using the internal override to force sRGB as an output profile for reftests. See Bug 452125. Note that we don't normally (outside of tests) set a default value of this preference, which means GetBoolPref will typically throw (and leave its out-param untouched). */ PRBool doSRGBOverride; rv = prefs->GetBoolPref(CMForceSRGBPrefName, &doSRGBOverride); if (NS_SUCCEEDED(rv) && doSRGBOverride) gCMSOutputProfile = GetCMSsRGBProfile(); if (!gCMSOutputProfile) { nsXPIDLCString fname; rv = prefs->GetCharPref(CMProfilePrefName, getter_Copies(fname)); if (NS_SUCCEEDED(rv) && !fname.IsEmpty()) { gCMSOutputProfile = qcms_profile_from_path(fname); } } } if (!gCMSOutputProfile) { gCMSOutputProfile = gfxPlatform::GetPlatform()->GetPlatformCMSOutputProfile(); } /* Determine if the profile looks bogus. If so, close the profile * and use sRGB instead. See bug 460629, */ if (gCMSOutputProfile && qcms_profile_is_bogus(gCMSOutputProfile)) { NS_ASSERTION(gCMSOutputProfile != GetCMSsRGBProfile(), "Builtin sRGB profile tagged as bogus!!!"); qcms_profile_release(gCMSOutputProfile); gCMSOutputProfile = nsnull; } if (!gCMSOutputProfile) { gCMSOutputProfile = GetCMSsRGBProfile(); } /* Precache the LUT16 Interpolations for the output profile. See bug 444661 for details. */ qcms_profile_precache_output_transform(gCMSOutputProfile); } return gCMSOutputProfile; }