| 5061 | } |
| 5062 | |
| 5063 | static int DecodeChunk(EXRImage *exr_image, const EXRHeader *exr_header, |
| 5064 | const OffsetData& offset_data, |
| 5065 | const unsigned char *head, const size_t size, |
| 5066 | std::string *err) { |
| 5067 | int num_channels = exr_header->num_channels; |
| 5068 | |
| 5069 | int num_scanline_blocks = 1; |
| 5070 | if (exr_header->compression_type == TINYEXR_COMPRESSIONTYPE_ZIP) { |
| 5071 | num_scanline_blocks = 16; |
| 5072 | } else if (exr_header->compression_type == TINYEXR_COMPRESSIONTYPE_PIZ) { |
| 5073 | num_scanline_blocks = 32; |
| 5074 | } else if (exr_header->compression_type == TINYEXR_COMPRESSIONTYPE_ZFP) { |
| 5075 | num_scanline_blocks = 16; |
| 5076 | |
| 5077 | #if TINYEXR_USE_ZFP |
| 5078 | tinyexr::ZFPCompressionParam zfp_compression_param; |
| 5079 | if (!FindZFPCompressionParam(&zfp_compression_param, |
| 5080 | exr_header->custom_attributes, |
| 5081 | int(exr_header->num_custom_attributes), err)) { |
| 5082 | return TINYEXR_ERROR_INVALID_HEADER; |
| 5083 | } |
| 5084 | #endif |
| 5085 | } |
| 5086 | |
| 5087 | if (exr_header->data_window.max_x < exr_header->data_window.min_x || |
| 5088 | exr_header->data_window.max_y < exr_header->data_window.min_y) { |
| 5089 | if (err) { |
| 5090 | (*err) += "Invalid data window.\n"; |
| 5091 | } |
| 5092 | return TINYEXR_ERROR_INVALID_DATA; |
| 5093 | } |
| 5094 | |
| 5095 | tinyexr_int64 data_width = |
| 5096 | 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); |
| 5097 | tinyexr_int64 data_height = |
| 5098 | 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); |
| 5099 | |
| 5100 | if (data_width <= 0) { |
| 5101 | if (err) { |
| 5102 | (*err) += "Invalid data window width.\n"; |
| 5103 | } |
| 5104 | return TINYEXR_ERROR_INVALID_DATA; |
| 5105 | } |
| 5106 | |
| 5107 | if (data_height <= 0) { |
| 5108 | if (err) { |
| 5109 | (*err) += "Invalid data window height.\n"; |
| 5110 | } |
| 5111 | return TINYEXR_ERROR_INVALID_DATA; |
| 5112 | } |
| 5113 | |
| 5114 | // Do not allow too large data_width and data_height. header invalid? |
| 5115 | { |
| 5116 | if ((data_width > TINYEXR_DIMENSION_THRESHOLD) || (data_height > TINYEXR_DIMENSION_THRESHOLD)) { |
| 5117 | if (err) { |
| 5118 | std::stringstream ss; |
| 5119 | ss << "data_with or data_height too large. data_width: " << data_width |
| 5120 | << ", " |
no test coverage detected