• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #include <stdint.h>
5 
6 #include "lcms2.h"
7 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)8 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
9   cmsHPROFILE srcProfile = cmsOpenProfileFromMem(data, size);
10   if (!srcProfile) return 0;
11 
12   cmsHPROFILE dstProfile = cmsCreate_sRGBProfile();
13   if (!dstProfile) {
14     cmsCloseProfile(srcProfile);
15     return 0;
16   }
17 
18   cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile);
19   cmsUInt32Number nSrcComponents = cmsChannelsOf(srcCS);
20   cmsUInt32Number srcFormat;
21   if (srcCS == cmsSigLabData) {
22     srcFormat =
23         COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0);
24   } else {
25     srcFormat =
26         COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_SH(1);
27   }
28 
29   cmsUInt32Number intent = 0;
30   cmsUInt32Number flags = 0;
31   cmsHTRANSFORM hTransform = cmsCreateTransform(
32       srcProfile, srcFormat, dstProfile, TYPE_BGR_8, intent, flags);
33   cmsCloseProfile(srcProfile);
34   cmsCloseProfile(dstProfile);
35   if (!hTransform) return 0;
36 
37   uint8_t output[4];
38   if (T_BYTES(srcFormat) == 0) {  // 0 means double
39     double input[nSrcComponents];
40     for (uint32_t i = 0; i < nSrcComponents; i++) input[i] = 0.5f;
41     cmsDoTransform(hTransform, input, output, 1);
42   } else {
43     uint8_t input[nSrcComponents];
44     for (uint32_t i = 0; i < nSrcComponents; i++) input[i] = 128;
45     cmsDoTransform(hTransform, input, output, 1);
46   }
47   cmsDeleteTransform(hTransform);
48 
49   return 0;
50 }
51