| 5137 | } |
| 5138 | |
| 5139 | static int DecodeChunk(EXRImage *exr_image, const EXRHeader *exr_header, |
| 5140 | const OffsetData& offset_data, |
| 5141 | const unsigned char *head, const size_t size, |
| 5142 | std::string *err) { |
| 5143 | int num_channels = exr_header->num_channels; |
| 5144 | |
| 5145 | int num_scanline_blocks = 1; |
| 5146 | if (exr_header->compression_type == TINYEXR_COMPRESSIONTYPE_ZIP) { |
| 5147 | num_scanline_blocks = 16; |
| 5148 | } else if (exr_header->compression_type == TINYEXR_COMPRESSIONTYPE_PIZ) { |
| 5149 | num_scanline_blocks = 32; |
| 5150 | } else if (exr_header->compression_type == TINYEXR_COMPRESSIONTYPE_ZFP) { |
| 5151 | num_scanline_blocks = 16; |
| 5152 | |
| 5153 | #if TINYEXR_USE_ZFP |
| 5154 | tinyexr::ZFPCompressionParam zfp_compression_param; |
| 5155 | if (!FindZFPCompressionParam(&zfp_compression_param, |
| 5156 | exr_header->custom_attributes, |
| 5157 | int(exr_header->num_custom_attributes), err)) { |
| 5158 | return TINYEXR_ERROR_INVALID_HEADER; |
| 5159 | } |
| 5160 | #endif |
| 5161 | } |
| 5162 | |
| 5163 | if (exr_header->data_window.max_x < exr_header->data_window.min_x || |
| 5164 | exr_header->data_window.max_y < exr_header->data_window.min_y) { |
| 5165 | if (err) { |
| 5166 | (*err) += "Invalid data window.\n"; |
| 5167 | } |
| 5168 | return TINYEXR_ERROR_INVALID_DATA; |
| 5169 | } |
| 5170 | |
| 5171 | tinyexr_int64 data_width = |
| 5172 | static_cast<tinyexr_int64>(exr_header->data_window.max_x) - static_cast<tinyexr_int64>(exr_header->data_window.min_x) + static_cast<tinyexr_int64>(1); |
| 5173 | tinyexr_int64 data_height = |
| 5174 | static_cast<tinyexr_int64>(exr_header->data_window.max_y) - static_cast<tinyexr_int64>(exr_header->data_window.min_y) + static_cast<tinyexr_int64>(1); |
| 5175 | |
| 5176 | if (data_width <= 0) { |
| 5177 | if (err) { |
| 5178 | (*err) += "Invalid data window width.\n"; |
| 5179 | } |
| 5180 | return TINYEXR_ERROR_INVALID_DATA; |
| 5181 | } |
| 5182 | |
| 5183 | if (data_height <= 0) { |
| 5184 | if (err) { |
| 5185 | (*err) += "Invalid data window height.\n"; |
| 5186 | } |
| 5187 | return TINYEXR_ERROR_INVALID_DATA; |
| 5188 | } |
| 5189 | |
| 5190 | // Do not allow too large data_width and data_height. header invalid? |
| 5191 | { |
| 5192 | if ((data_width > TINYEXR_DIMENSION_THRESHOLD) || (data_height > TINYEXR_DIMENSION_THRESHOLD)) { |
| 5193 | if (err) { |
| 5194 | std::stringstream ss; |
| 5195 | ss << "data_with or data_height too large. data_width: " << data_width |
| 5196 | << ", " |
no test coverage detected