RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
Solo.cpp
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2017-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
21#include "adt/Array1DRef.h"
22#include "adt/Casts.h"
23#ifndef IMPL
24#error IMPL must be defined to one of rawspeeds huffman table implementations
25#endif
26
30#include "codes/PrefixCodeDecoder.h" // IWYU pragma: keep
32#include "codes/PrefixCodeLUTDecoder.h" // IWYU pragma: keep
33#include "codes/PrefixCodeLookupDecoder.h" // IWYU pragma: keep
34#include "codes/PrefixCodeTreeDecoder.h" // IWYU pragma: keep
35#include "codes/PrefixCodeVectorDecoder.h" // IWYU pragma: keep
37#include "io/Buffer.h"
38#include "io/ByteStream.h"
39#include "io/Endianness.h"
40#include <cassert>
41#include <cstdint>
42#include <cstdio>
43
44namespace rawspeed {
45struct BaselineCodeTag;
46struct VC5CodeTag;
47} // namespace rawspeed
48
49namespace {
50
51template <typename Pump, bool IsFullDecode, typename HT>
53 Pump bits(input);
54 while (true)
55 ht.template decode<Pump, IsFullDecode>(bits);
56 // FIXME: do we need to escape the result to avoid dead code elimination?
57}
58
59template <typename Pump, typename HT>
61 if (ht.isFullDecode())
62 workloop<Pump, /*IsFullDecode=*/true>(input, ht);
63 else
64 workloop<Pump, /*IsFullDecode=*/false>(input, ht);
65}
66
67template <typename CodeTag> void checkFlavour(rawspeed::ByteStream bs) {
68#ifndef BACKIMPL
70#else
71 const auto ht = createPrefixCodeDecoder<
72 rawspeed::IMPL<CodeTag, rawspeed::BACKIMPL<CodeTag>>>(bs);
73#endif
74
75 // Which bit pump should we use?
76 const auto format = bs.getByte();
77 const auto input = bs.peekRemainingBuffer().getAsArray1DRef();
78 switch (format) {
79 case 0:
81 break;
82 case 1:
84 break;
85 case 2:
87 break;
88 default:
89 ThrowRSE("Unknown bit pump");
90 }
91}
92
93} // namespace
94
95extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size);
96
97extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
98 assert(Data);
99
100 try {
101 const rawspeed::Buffer b(
105
106 // Which flavor?
107 switch (bs.getByte()) {
108 case 0:
110 break;
111 case 1:
113 break;
114 default:
115 ThrowRSE("Unknown flavor");
116 }
117 } catch (const rawspeed::RawspeedException&) {
118 return 0;
119 }
120
121 __builtin_unreachable();
122}
#define ThrowRSE(...)
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
Definition Solo.cpp:97
assert(dim.area() >=area)
Array1DRef< const uint8_t > getAsArray1DRef() const
Definition Buffer.h:70
Buffer peekRemainingBuffer() const
Definition ByteStream.h:108
static T createPrefixCodeDecoder(rawspeed::ByteStream &bs)
Definition Common.h:147
void workloop(rawspeed::Array1DRef< const uint8_t > input, const HT &ht)
Definition Solo.cpp:52
void checkPump(rawspeed::Array1DRef< const uint8_t > input, const HT &ht)
Definition Solo.cpp:60
void checkFlavour(rawspeed::ByteStream bs)
Definition Solo.cpp:67
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)
Definition Casts.h:32