decode_basic_info_fuzzer.cc (1591B)
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 #include <jxl/decode.h> 7 #include <stdint.h> 8 9 namespace jpegxl { 10 namespace tools { 11 12 int TestOneInput(const uint8_t* data, size_t size) { 13 JxlDecoderStatus status; 14 JxlDecoder* dec = JxlDecoderCreate(nullptr); 15 JxlDecoderSubscribeEvents(dec, JXL_DEC_BASIC_INFO | JXL_DEC_COLOR_ENCODING); 16 JxlDecoderSetInput(dec, data, size); 17 18 status = JxlDecoderProcessInput(dec); 19 20 if (status != JXL_DEC_BASIC_INFO) { 21 JxlDecoderDestroy(dec); 22 return 0; 23 } 24 25 JxlBasicInfo info; 26 status = JxlDecoderGetBasicInfo(dec, &info); 27 bool have_basic_info = (status == JXL_DEC_SUCCESS); 28 29 if (have_basic_info) { 30 if (info.alpha_bits != 0) { 31 for (int i = 0; i < info.num_extra_channels; ++i) { 32 JxlExtraChannelInfo extra; 33 JxlDecoderGetExtraChannelInfo(dec, 0, &extra); 34 } 35 } 36 } 37 status = JxlDecoderProcessInput(dec); 38 39 if (status != JXL_DEC_COLOR_ENCODING) { 40 JxlDecoderDestroy(dec); 41 return 0; 42 } 43 44 JxlDecoderGetColorAsEncodedProfile(dec, JXL_COLOR_PROFILE_TARGET_ORIGINAL, 45 nullptr); 46 size_t dec_profile_size; 47 JxlDecoderGetICCProfileSize(dec, JXL_COLOR_PROFILE_TARGET_ORIGINAL, 48 &dec_profile_size); 49 50 JxlDecoderDestroy(dec); 51 return 0; 52 } 53 54 } // namespace tools 55 } // namespace jpegxl 56 57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 58 return jpegxl::tools::TestOneInput(data, size); 59 }