/src/librawspeed/fuzz/librawspeed/decompressors/Cr2LJpegDecoder.cpp
Line | Count | Source |
1 | | /* |
2 | | RawSpeed - RAW file decoder. |
3 | | |
4 | | Copyright (C) 2017 Roman Lebedev |
5 | | |
6 | | This library is free software; you can redistribute it and/or |
7 | | modify it under the terms of the GNU Lesser General Public |
8 | | License as published by the Free Software Foundation; either |
9 | | version 2 of the License, or (at your option) any later version. |
10 | | |
11 | | This library is distributed in the hope that it will be useful, |
12 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | | Lesser General Public License for more details. |
15 | | |
16 | | You should have received a copy of the GNU Lesser General Public |
17 | | License along with this library; if not, write to the Free Software |
18 | | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | | */ |
20 | | |
21 | | #include "decompressors/Cr2LJpegDecoder.h" |
22 | | #include "MemorySanitizer.h" |
23 | | #include "adt/Casts.h" |
24 | | #include "common/RawImage.h" |
25 | | #include "common/RawspeedException.h" |
26 | | #include "decompressors/Cr2Decompressor.h" |
27 | | #include "fuzz/Common.h" |
28 | | #include "io/Buffer.h" |
29 | | #include "io/ByteStream.h" |
30 | | #include "io/Endianness.h" |
31 | | #include <cassert> |
32 | | #include <cstdint> |
33 | | #include <cstdio> |
34 | | |
35 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size); |
36 | | |
37 | 22.5k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) { |
38 | 22.5k | assert(Data); |
39 | | |
40 | 22.5k | try { |
41 | 22.5k | const rawspeed::Buffer b( |
42 | 22.5k | Data, rawspeed::implicit_cast<rawspeed::Buffer::size_type>(Size)); |
43 | 22.5k | const rawspeed::DataBuffer db(b, rawspeed::Endianness::little); |
44 | 22.5k | rawspeed::ByteStream bs(db); |
45 | | |
46 | 22.5k | rawspeed::RawImage mRaw(CreateRawImage(bs)); |
47 | | |
48 | 22.5k | using slice_type = uint16_t; |
49 | 22.5k | const auto numSlices = bs.get<slice_type>(); |
50 | 22.5k | const auto sliceWidth = bs.get<slice_type>(); |
51 | 22.5k | const auto lastSliceWidth = bs.get<slice_type>(); |
52 | | |
53 | 22.5k | const rawspeed::Cr2SliceWidths slicing(numSlices, sliceWidth, |
54 | 22.5k | lastSliceWidth); |
55 | | |
56 | 22.5k | rawspeed::Cr2LJpegDecoder c(bs, mRaw); |
57 | 22.5k | mRaw->createData(); |
58 | 22.5k | c.decode(slicing); |
59 | | |
60 | 22.5k | rawspeed::MSan::CheckMemIsInitialized( |
61 | 22.5k | mRaw->getByteDataAsUncroppedArray2DRef()); |
62 | 22.5k | } catch (const rawspeed::RawspeedException&) { // NOLINT(bugprone-empty-catch) |
63 | | // Exceptions are good, crashes are bad. |
64 | 20.9k | } |
65 | | |
66 | 22.5k | return 0; |
67 | 22.5k | } |