53 if (!
mRaw->dim.hasPositiveArea())
56#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
58 if (
mRaw->dim.x > 19440 ||
mRaw->dim.y > 8842) {
59 ThrowRDE(
"Unexpected image dimensions found: (%i; %i)", mRaw->dim.x,
67 ThrowRDE(
"Image did not start with SOI. Probably not an LJPEG");
83 ThrowRDE(
"Found second DHT marker after SOS");
87 FoundMarkers.DHT =
true;
91 ThrowRDE(
"Found second SOF marker after SOS");
96 FoundMarkers.SOF =
true;
100 ThrowRDE(
"Found second SOS marker");
101 if (!FoundMarkers.DHT)
102 ThrowRDE(
"Did not find DHT marker before SOS.");
103 if (!FoundMarkers.SOF)
104 ThrowRDE(
"Did not find SOF marker before SOS.");
106 FoundMarkers.SOS =
true;
113 if (FoundMarkers.DRI)
114 ThrowRDE(
"Found second DRI marker");
116 FoundMarkers.DRI =
true;
123 if (!FoundMarkers.SOS)
124 ThrowRDE(
"Did not find SOS marker.");
133 if (sof->
prec < 2 || sof->
prec > 16)
136 if (sof->
h == 0 || sof->
w == 0)
137 ThrowRDE(
"Frame width or height set to zero");
139 if (sof->
cps > 4 || sof->
cps < 1)
140 ThrowRDE(
"Only from 1 to 4 components are supported.");
142 if (sof->
cps <
mRaw->getCpp()) {
143 ThrowRDE(
"Component count should be no less than sample count (%u vs %u).",
148 ThrowRDE(
"Component count should be no greater than row length (%u vs %d).",
159 frame.compInfo[i].superV = subs & 0xf;
160 frame.compInfo[i].superH = subs >> 4;
162 if (
frame.compInfo[i].superV < 1 ||
frame.compInfo[i].superV > 4)
163 ThrowRDE(
"Horizontal sampling factor is invalid.");
165 if (
frame.compInfo[i].superH < 1 ||
frame.compInfo[i].superH > 4)
166 ThrowRDE(
"Horizontal sampling factor is invalid.");
170 ThrowRDE(
"Quantized components not supported.");
173 if (
static_cast<int>(sof->
compInfo[0].superH) !=
174 mRaw->metadata.subsampling.x ||
175 static_cast<int>(sof->
compInfo[0].superV) !=
mRaw->metadata.subsampling.y)
176 ThrowRDE(
"LJpeg's subsampling does not match image's subsampling.");
185 ThrowRDE(
"Invalid SOS header length.");
188 ThrowRDE(
"Component number mismatch.");
195 ThrowRDE(
"Invalid Huffman table selection.");
199 if (
frame.compInfo[j].componentId == cs)
204 ThrowRDE(
"Invalid Component Selector");
206 frame.compInfo[ciIndex].dcTblNo = td;
213 ThrowRDE(
"Invalid predictor mode.");
221 ThrowRDE(
"Invalid Point transform.");
223 ThrowRDE(
"Point transform not supported.");
227 input.skipBytes(scanLength);
234 if (
uint32_t htClass = b >> 4; htClass != 0)
235 ThrowRDE(
"Unsupported Table class.");
238 if (htIndex >=
huff.size())
239 ThrowRDE(
"Invalid huffman table destination id.");
241 if (
huff[htIndex] !=
nullptr)
242 ThrowRDE(
"Duplicate table definition");
255 const auto codesBuf = dht.
getBuffer(nCodes);
265 if (!
huff[htIndex]) {
268 auto dHT = std::make_unique<PrefixCodeDecoder<>>(std::move(hc));
270 huff[htIndex] = dHT.get();
278 ThrowRDE(
"Invalid DRI header length.");
286 ThrowRDE(
"(Noskip) Expected marker not found. Probably corrupt file.");
assert(dim.area() >=area)
uint16_t numMCUsPerRestartInterval
virtual ByteStream::size_type decodeScan()=0
void parseSOS(ByteStream data)
void parseSOF(ByteStream data, SOFInfo *i)
std::vector< std::unique_ptr< const PrefixCodeDecoder<> > > PrefixCodeDecoderStore
virtual bool erratumImplicitEOIMarkerAfterScan() const
JpegMarker getNextMarker(bool allowskip)
AbstractLJpegDecoder(ByteStream bs, RawImage img)
void parseDRI(ByteStream dri)
std::vector< std::unique_ptr< const HuffmanCode< BaselineCodeTag > > > huffmanCodeStore
void parseDHT(ByteStream data)
std::array< const PrefixCodeDecoder<> *, 4 > huff
virtual void anchor() const
size_type RAWSPEED_READONLY getRemainSize() const
Buffer getBuffer(size_type size_)
void skipBytes(size_type nbytes)
uint32_t setNCodesPerLength(Buffer data)
void setCodeValues(Array1DRef< const typename Traits::CodeValueTy > data)
std::array< JpegComponentInfo, 4 > compInfo
Optional< ByteStream > advanceToNextMarker(ByteStream input, bool skipPadding)
Optional< JpegMarker > peekMarker(ByteStream input)