|
| 1 | +/* Copyright 2023 Google LLC |
| 2 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +you may not use this file except in compliance with the License. |
| 4 | +You may obtain a copy of the License at |
| 5 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +Unless required by applicable law or agreed to in writing, software |
| 7 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 8 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 9 | +See the License for the specific language governing permissions and |
| 10 | +limitations under the License. |
| 11 | +*/ |
| 12 | + |
| 13 | +#include <stdint.h> |
| 14 | +#include "lcms2.h" |
| 15 | + |
| 16 | + |
| 17 | +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 18 | + |
| 19 | + if (size < 8){ |
| 20 | + return 0; |
| 21 | + } |
| 22 | + |
| 23 | + cmsContext context = cmsCreateContext(NULL, (void *)data); |
| 24 | + |
| 25 | + uint32_t Row = *((uint32_t *)data); |
| 26 | + uint32_t Col = *((uint32_t *)data+1); |
| 27 | + |
| 28 | + /* Write */ |
| 29 | + cmsHANDLE it8; |
| 30 | + cmsInt32Number i; |
| 31 | + |
| 32 | + it8 = cmsIT8Alloc(0); |
| 33 | + if (it8 == NULL) return 0; |
| 34 | + |
| 35 | + cmsIT8SetSheetType(it8, "LCMS/TESTING"); |
| 36 | + cmsIT8SetPropertyStr(it8, "ORIGINATOR", "1 2 3 4"); |
| 37 | + cmsIT8SetPropertyUncooked(it8, "DESCRIPTOR", "1234"); |
| 38 | + cmsIT8SetPropertyStr(it8, "MANUFACTURER", "3"); |
| 39 | + cmsIT8SetPropertyDbl(it8, "CREATED", data[0] / 255.0); |
| 40 | + cmsIT8SetPropertyDbl(it8, "SERIAL", data[1] / 255.0); |
| 41 | + cmsIT8SetPropertyHex(it8, "MATERIAL", 0x123); |
| 42 | + |
| 43 | + cmsIT8SetPropertyDbl(it8, "NUMBER_OF_SETS", 10); |
| 44 | + cmsIT8SetPropertyDbl(it8, "NUMBER_OF_FIELDS", Row); |
| 45 | + |
| 46 | + cmsIT8SetDataFormat(it8, 0, "SAMPLE_ID"); |
| 47 | + cmsIT8SetDataFormat(it8, 1, "RGB_R"); |
| 48 | + cmsIT8SetDataFormat(it8, 2, "RGB_G"); |
| 49 | + cmsIT8SetDataFormat(it8, 3, "RGB_B"); |
| 50 | + |
| 51 | + for (i=0; i < 10; i++) { |
| 52 | + |
| 53 | + char Patch[20]; |
| 54 | + |
| 55 | + sprintf(Patch, "P%d", i); |
| 56 | + |
| 57 | + cmsIT8SetDataRowCol(it8, i, 0, Patch); |
| 58 | + cmsIT8SetDataRowColDbl(it8, i, 1, i); |
| 59 | + cmsIT8SetDataRowColDbl(it8, i, 2, i); |
| 60 | + cmsIT8SetDataRowColDbl(it8, i, 3, i); |
| 61 | + } |
| 62 | + |
| 63 | + cmsIT8SaveToFile(it8, "TEST.IT8"); |
| 64 | + cmsIT8Free(it8); |
| 65 | + |
| 66 | + it8 = cmsIT8LoadFromFile(0, "TEST.IT8"); |
| 67 | + if (it8 == NULL) return 0; |
| 68 | + |
| 69 | + /* Read */ |
| 70 | + cmsIT8GetDataRowColDbl(it8,Row,Col); |
| 71 | + cmsIT8GetPropertyDbl(it8, "DESCRIPTOR"); |
| 72 | + cmsIT8GetDataDbl(it8, "P3", "RGB_G"); |
| 73 | + |
| 74 | + cmsIT8Free(it8); |
| 75 | + return 1; |
| 76 | +} |
0 commit comments