RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
UncompressedDecompressor.cpp
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2023 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
22#include "MemorySanitizer.h"
23#include "adt/Casts.h"
24#include "adt/Point.h"
26#include "common/RawImage.h"
28#include "fuzz/Common.h"
29#include "io/Buffer.h"
30#include "io/ByteStream.h"
31#include "io/Endianness.h"
32#include <cassert>
33#include <cstddef>
34#include <cstdint>
35
36extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size);
37
38extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
39 assert(Data);
40
41 try {
42 const rawspeed::Buffer b(
46
48
49 int inputPitchBytes = bs.getI32();
50 int bitPerPixel = bs.getI32();
51 rawspeed::BitOrder order = [&bs]() {
52 switch (int val = bs.getI32()) {
53 case static_cast<int>(rawspeed::BitOrder::LSB):
54 case static_cast<int>(rawspeed::BitOrder::MSB):
55 case static_cast<int>(rawspeed::BitOrder::MSB16):
56 case static_cast<int>(rawspeed::BitOrder::MSB32):
57 case static_cast<int>(rawspeed::BitOrder::JPEG):
58 return rawspeed::BitOrder(val);
59 default:
60 ThrowRSE("Unknown bit order: %i", val);
61 }
62 __builtin_unreachable();
63 }();
64
66 bs.getSubStream(/*offset=*/0), mRaw,
67 rawspeed::iRectangle2D({0, 0}, mRaw->dim), inputPitchBytes, bitPerPixel,
68 order);
69 mRaw->createData();
71
74 } catch (const rawspeed::RawspeedException&) { // NOLINT(bugprone-empty-catch)
75 // Exceptions are good, crashes are bad.
76 }
77
78 return 0;
79}
#define ThrowRSE(...)
assert(dim.area() >=area)
ByteStream getSubStream(size_type offset, size_type size_) const
Definition ByteStream.h:54
Array2DRef< std::byte > getByteDataAsUncroppedArray2DRef() noexcept
Definition RawImage.h:330
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
rawspeed::RawImage CreateRawImage(rawspeed::ByteStream &bs)
Definition Common.cpp:31
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)
Definition Casts.h:32
static void CheckMemIsInitialized(const void *addr, size_t size)