Skip to content

Commit

Permalink
fix crash when encoding tiled unci images
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Nov 15, 2024
1 parent 2a764da commit e18c15e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 8 additions & 0 deletions libheif/image-items/image_item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,19 @@ std::shared_ptr<HeifFile> ImageItem::get_file() const

heif_property_id ImageItem::add_property(std::shared_ptr<Box> property, bool essential)
{
// TODO: is this correct? What happens when add_property does deduplicate the property?
m_properties.push_back(property);
return get_file()->add_property(get_id(), property, essential);
}


heif_property_id ImageItem::add_property_without_deduplication(std::shared_ptr<Box> property, bool essential)
{
m_properties.push_back(property);
return get_file()->add_property_without_deduplication(get_id(), property, essential);
}


Error ImageItem::init_decoder_from_item(heif_item_id id)
{
m_id = id;
Expand Down
2 changes: 2 additions & 0 deletions libheif/image-items/image_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class ImageItem : public ErrorBuffer

heif_property_id add_property(std::shared_ptr<Box> property, bool essential);

heif_property_id add_property_without_deduplication(std::shared_ptr<Box> property, bool essential);

void set_resolution(uint32_t w, uint32_t h)
{
m_width = w;
Expand Down
16 changes: 8 additions & 8 deletions libheif/image-items/unc_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,19 +336,19 @@ Result<std::shared_ptr<ImageItem_uncompressed>> ImageItem_uncompressed::add_unci
assert(headers.uncC);

if (headers.uncC) {
file->add_property(unci_id, headers.uncC, true);
unci_image->add_property(headers.uncC, true);
}

if (headers.cmpd) {
file->add_property(unci_id, headers.cmpd, true);
unci_image->add_property(headers.cmpd, true);
}

// Add `ispe` property

file->add_ispe_property(unci_id,
static_cast<uint32_t>(parameters->image_width),
static_cast<uint32_t>(parameters->image_height),
true);
auto ispe = std::make_shared<Box_ispe>();
ispe->set_size(static_cast<uint32_t>(parameters->image_width),
static_cast<uint32_t>(parameters->image_height));
unci_image->add_property(ispe, true);

if (parameters->compression != heif_unci_compression_off) {
auto icef = std::make_shared<Box_icef>();
Expand All @@ -374,8 +374,8 @@ Result<std::shared_ptr<ImageItem_uncompressed>> ImageItem_uncompressed::add_unci
assert(false);
}

file->add_property(unci_id, cmpC, true);
file->add_property_without_deduplication(unci_id, icef, true); // icef is empty. A normal add_property() would lead to a wrong deduplication.
unci_image->add_property(cmpC, true);
unci_image->add_property_without_deduplication(icef, true); // icef is empty. A normal add_property() would lead to a wrong deduplication.
}

// Create empty image. If we use compression, we append the data piece by piece.
Expand Down

0 comments on commit e18c15e

Please sign in to comment.