From 0f265bd4a6096760f8fe9671a32f82f98b3cea6d Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Thu, 12 Oct 2023 20:19:20 +0200 Subject: [PATCH] fix type conversion warnings --- libheif/heif_regions.cc | 4 ++-- libheif/jpeg2000.cc | 2 +- libheif/uncompressed_image.cc | 22 +++++++++++++++------- libheif/uncompressed_image.h | 2 +- libheif/vvc.cc | 4 ++-- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/libheif/heif_regions.cc b/libheif/heif_regions.cc index f2ceb83a8f..139d25bcec 100644 --- a/libheif/heif_regions.cc +++ b/libheif/heif_regions.cc @@ -342,7 +342,7 @@ struct heif_error heif_region_item_add_region_inline_mask(struct heif_region_ite for (uint32_t y = 0; y < mask_height; y++) { for (uint32_t x = 0; x < mask_width; x++) { uint8_t mask_bit = p[y * stride + x] & 0x80; // use high-order bit of the 8-bit mask value as binary mask value - region->mask_data.data()[pixel_index/8] |= (mask_bit >> (pixel_index % 8)); + region->mask_data.data()[pixel_index/8] |= uint8_t(mask_bit >> (pixel_index % 8)); pixel_index++; } @@ -682,7 +682,7 @@ static struct heif_error heif_region_get_inline_mask_image(const struct heif_reg for (uint32_t x = 0; x < width; x++) { uint64_t mask_byte = pixel_index / 8; - uint8_t pixel_bit = 0x80U >> (pixel_index % 8); + uint8_t pixel_bit = uint8_t(0x80U >> (pixel_index % 8)); p[y * stride + x] = (mask_data[mask_byte] & pixel_bit) ? 255 : 0; diff --git a/libheif/jpeg2000.cc b/libheif/jpeg2000.cc index 296a9f5474..dc96c2cc16 100644 --- a/libheif/jpeg2000.cc +++ b/libheif/jpeg2000.cc @@ -357,7 +357,7 @@ JPEG2000_SIZ_segment jpeg2000_get_SIZ_segment(const HeifFile& file, heif_item_id JPEG2000_SIZ_segment::component comp; comp.precision = data[42 + c * 3]; comp.is_signed = (comp.precision & 0x80); - comp.precision = (comp.precision & 0x7F) + 1; + comp.precision = uint8_t((comp.precision & 0x7F) + 1); comp.h_separation = data[43 + c * 3]; comp.v_separation = data[44 + c * 3]; siz.components.push_back(comp); diff --git a/libheif/uncompressed_image.cc b/libheif/uncompressed_image.cc index a0e987e62b..6281883329 100644 --- a/libheif/uncompressed_image.cc +++ b/libheif/uncompressed_image.cc @@ -192,7 +192,7 @@ Error Box_uncC::parse(BitstreamRange& range) for (unsigned int i = 0; i < component_count && !range.error() && !range.eof(); i++) { Component component; component.component_index = range.read16(); - component.component_bit_depth = range.read8() + 1; + component.component_bit_depth = uint16_t(range.read8() + 1); component.component_format = range.read8(); component.component_align_size = range.read8(); m_components.push_back(component); @@ -281,8 +281,12 @@ Error Box_uncC::write(StreamWriter& writer) const writer.write32(m_profile); writer.write32((uint32_t) m_components.size()); for (const auto& component : m_components) { + if (component.component_bit_depth < 1 || component.component_bit_depth > 256) { + return {heif_error_Invalid_input, heif_suberror_Invalid_parameter_value, "component bit-depth out of range [1..256]"}; + } + writer.write16(component.component_index); - writer.write8(component.component_bit_depth - 1); + writer.write8(uint8_t(component.component_bit_depth - 1)); writer.write8(component.component_format); writer.write8(component.component_align_size); } @@ -290,11 +294,11 @@ Error Box_uncC::write(StreamWriter& writer) const writer.write8(m_interleave_type); writer.write8(m_block_size); uint8_t flags = 0; - flags |= (m_components_little_endian ? 1 : 0) << 7; - flags |= (m_block_pad_lsb ? 1 : 0) << 6; - flags |= (m_block_little_endian ? 1 : 0) << 5; - flags |= (m_block_reversed ? 1 : 0) << 4; - flags |= (m_pad_unknown ? 1 : 0) << 3; + flags |= (m_components_little_endian ? 0x80 : 0); + flags |= (m_block_pad_lsb ? 0x40 : 0); + flags |= (m_block_little_endian ? 0x20 : 0); + flags |= (m_block_reversed ? 0x10 : 0); + flags |= (m_pad_unknown ? 0x08 : 0); writer.write8(flags); writer.write32(m_pixel_size); writer.write32(m_row_align_size); @@ -415,6 +419,10 @@ static Error get_heif_chroma_uncompressed(std::shared_ptr& uncC, std:: uint16_t component_index = component.component_index; uint16_t component_type = cmpd->get_components()[component_index].component_type; + if (component_type >= 16) { + return { heif_error_Unsupported_feature, heif_suberror_Invalid_parameter_value, "a component_type >= 16 is not supported"}; + } + componentSet |= (1 << component_type); } diff --git a/libheif/uncompressed_image.h b/libheif/uncompressed_image.h index 64c082449a..c7bfd4dd7c 100644 --- a/libheif/uncompressed_image.h +++ b/libheif/uncompressed_image.h @@ -83,7 +83,7 @@ class Box_uncC : public FullBox struct Component { uint16_t component_index; - uint8_t component_bit_depth; + uint16_t component_bit_depth; // range [1..256] uint8_t component_format; uint8_t component_align_size; }; diff --git a/libheif/vvc.cc b/libheif/vvc.cc index ecea732287..f778324c1b 100644 --- a/libheif/vvc.cc +++ b/libheif/vvc.cc @@ -37,7 +37,7 @@ Error Box_vvcC::parse(BitstreamRange& range) byte = range.read8(); c.constantFrameRate = (byte & 0xc0) >> 6; c.numTemporalLayers = (byte & 0x38) >> 3; - c.lengthSize = (byte & 0x06) + 1; + c.lengthSize = uint8_t((byte & 0x06) + 1); c.ptl_present_flag = (byte & 0x01); // assert(c.ptl_present_flag == false); // TODO (removed the assert since it will trigger the fuzzers) @@ -46,7 +46,7 @@ Error Box_vvcC::parse(BitstreamRange& range) c.chroma_format_idc = (byte & 0x60) >> 5; c.bit_depth_present_flag = (byte & 0x10); - c.bit_depth = ((byte & 0x0e) >> 1) + 8; + c.bit_depth = uint8_t(((byte & 0x0e) >> 1) + 8); c.numOfArrays = range.read8();