Skip to content

Commit aa42dfc

Browse files
committed
add decode_next_image() to plugin API, passing the security limits
1 parent 4e6fd87 commit aa42dfc

File tree

8 files changed

+31
-11
lines changed

8 files changed

+31
-11
lines changed

libheif/api/libheif/heif_plugin.h

+3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ struct heif_decoder_plugin
109109
const char* id_name;
110110

111111
// --- version 4 functions will follow below ... ---
112+
113+
struct heif_error (* decode_next_image)(void* decoder, struct heif_image** out_img,
114+
const struct heif_security_limits* limits);
112115
};
113116

114117

libheif/codecs/decoder.cc

+15-4
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ Result<std::vector<uint8_t>> Decoder::get_compressed_data() const
243243

244244

245245
Result<std::shared_ptr<HeifPixelImage>>
246-
Decoder::decode_single_frame_from_compressed_data(const struct heif_decoding_options& options)
246+
Decoder::decode_single_frame_from_compressed_data(const struct heif_decoding_options& options,
247+
const struct heif_security_limits* limits)
247248
{
248249
const struct heif_decoder_plugin* decoder_plugin = get_decoder(get_compression_format(), options.decoder_id);
249250
if (!decoder_plugin) {
@@ -285,9 +286,19 @@ Decoder::decode_single_frame_from_compressed_data(const struct heif_decoding_opt
285286

286287
heif_image* decoded_img = nullptr;
287288

288-
err = decoder_plugin->decode_image(decoder, &decoded_img);
289-
if (err.code != heif_error_Ok) {
290-
return Error(err.code, err.subcode, err.message);
289+
if (decoder_plugin->plugin_api_version >= 4 &&
290+
decoder_plugin->decode_next_image != nullptr) {
291+
292+
err = decoder_plugin->decode_next_image(decoder, &decoded_img, limits);
293+
if (err.code != heif_error_Ok) {
294+
return Error(err.code, err.subcode, err.message);
295+
}
296+
}
297+
else {
298+
err = decoder_plugin->decode_image(decoder, &decoded_img);
299+
if (err.code != heif_error_Ok) {
300+
return Error(err.code, err.subcode, err.message);
301+
}
291302
}
292303

293304
if (!decoded_img) {

libheif/codecs/decoder.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class Decoder
9494
// --- decoding
9595

9696
virtual Result<std::shared_ptr<HeifPixelImage>>
97-
decode_single_frame_from_compressed_data(const struct heif_decoding_options& options);
97+
decode_single_frame_from_compressed_data(const struct heif_decoding_options& options,
98+
const struct heif_security_limits* limits);
9899

99100
private:
100101
DataExtent m_data_extent;

libheif/codecs/uncompressed/unc_dec.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ bool Decoder_uncompressed::has_alpha_component() const
164164

165165

166166
Result<std::shared_ptr<HeifPixelImage>>
167-
Decoder_uncompressed::decode_single_frame_from_compressed_data(const struct heif_decoding_options& options)
167+
Decoder_uncompressed::decode_single_frame_from_compressed_data(const struct heif_decoding_options& options,
168+
const struct heif_security_limits* limits)
168169
{
169170
UncompressedImageCodec::unci_properties properties;
170171
properties.uncC = m_uncC;
@@ -173,7 +174,7 @@ Decoder_uncompressed::decode_single_frame_from_compressed_data(const struct heif
173174

174175
auto decodeResult = UncompressedImageCodec::decode_uncompressed_image(properties,
175176
get_data_extent(),
176-
heif_get_global_security_limits()); // TODO: use correct security limits
177+
limits);
177178

178179
if (decodeResult.error) {
179180
return decodeResult.error;

libheif/codecs/uncompressed/unc_dec.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class Decoder_uncompressed : public Decoder
5353
Result<std::vector<uint8_t>> read_bitstream_configuration_data() const override;
5454

5555
Result<std::shared_ptr<HeifPixelImage>>
56-
decode_single_frame_from_compressed_data(const struct heif_decoding_options& options) override;
56+
decode_single_frame_from_compressed_data(const struct heif_decoding_options& options,
57+
const struct heif_security_limits* limits) override;
5758

5859
private:
5960
const std::shared_ptr<const Box_uncC> m_uncC;

libheif/image-items/image_item.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,8 @@ Result<std::shared_ptr<HeifPixelImage>> ImageItem::decode_compressed_image(const
899899

900900
decoder->set_data_extent(std::move(extent));
901901

902-
return decoder->decode_single_frame_from_compressed_data(options);
902+
return decoder->decode_single_frame_from_compressed_data(options,
903+
get_context()->get_security_limits());
903904
}
904905

905906

libheif/image-items/tiled.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,8 @@ ImageItem_Tiled::decode_grid_tile(const heif_decoding_options& options, uint32_t
831831

832832
m_tile_decoder->set_data_extent(std::move(*extentResult));
833833

834-
return m_tile_decoder->decode_single_frame_from_compressed_data(options);
834+
return m_tile_decoder->decode_single_frame_from_compressed_data(options,
835+
get_context()->get_security_limits());
835836
}
836837

837838

libheif/sequences/track_visual.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ Result<std::shared_ptr<HeifPixelImage>> Track_Visual::decode_next_image_sample(c
9595

9696
decoder->set_data_extent(chunk->get_data_extent_for_sample(m_next_sample_to_be_processed));
9797

98-
Result<std::shared_ptr<HeifPixelImage>> decodingResult = decoder->decode_single_frame_from_compressed_data(options);
98+
Result<std::shared_ptr<HeifPixelImage>> decodingResult = decoder->decode_single_frame_from_compressed_data(options,
99+
m_heif_context->get_security_limits());
99100
if (decodingResult.error) {
100101
m_next_sample_to_be_processed++;
101102
return decodingResult.error;

0 commit comments

Comments
 (0)