| 5972 | } |
| 5973 | |
| 5974 | static int DecodeEXRImage(EXRImage *exr_image, const EXRHeader *exr_header, |
| 5975 | const unsigned char *head, |
| 5976 | const unsigned char *marker, const size_t size, |
| 5977 | const char **err) { |
| 5978 | if (exr_image == NULL || exr_header == NULL || head == NULL || |
| 5979 | marker == NULL || (size <= tinyexr::kEXRVersionSize)) { |
| 5980 | tinyexr::SetErrorMessage("Invalid argument for DecodeEXRImage().", err); |
| 5981 | return TINYEXR_ERROR_INVALID_ARGUMENT; |
| 5982 | } |
| 5983 | |
| 5984 | int num_scanline_blocks = 1; |
| 5985 | if (exr_header->compression_type == TINYEXR_COMPRESSIONTYPE_ZIP) { |
| 5986 | num_scanline_blocks = 16; |
| 5987 | } else if (exr_header->compression_type == TINYEXR_COMPRESSIONTYPE_PIZ) { |
| 5988 | num_scanline_blocks = 32; |
| 5989 | } else if (exr_header->compression_type == TINYEXR_COMPRESSIONTYPE_ZFP) { |
| 5990 | num_scanline_blocks = 16; |
| 5991 | } |
| 5992 | |
| 5993 | if (exr_header->data_window.max_x < exr_header->data_window.min_x || |
| 5994 | exr_header->data_window.max_x - exr_header->data_window.min_x == |
| 5995 | std::numeric_limits<int>::max()) { |
| 5996 | // Issue 63 |
| 5997 | tinyexr::SetErrorMessage("Invalid data width value", err); |
| 5998 | return TINYEXR_ERROR_INVALID_DATA; |
| 5999 | } |
| 6000 | tinyexr_int64 data_width = |
| 6001 | 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); |
| 6002 | if (data_width <= 0) { |
| 6003 | tinyexr::SetErrorMessage("Invalid data window width value", err); |
| 6004 | return TINYEXR_ERROR_INVALID_DATA; |
| 6005 | } |
| 6006 | |
| 6007 | if (exr_header->data_window.max_y < exr_header->data_window.min_y || |
| 6008 | exr_header->data_window.max_y - exr_header->data_window.min_y == |
| 6009 | std::numeric_limits<int>::max()) { |
| 6010 | tinyexr::SetErrorMessage("Invalid data height value", err); |
| 6011 | return TINYEXR_ERROR_INVALID_DATA; |
| 6012 | } |
| 6013 | tinyexr_int64 data_height = |
| 6014 | 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); |
| 6015 | |
| 6016 | if (data_height <= 0) { |
| 6017 | tinyexr::SetErrorMessage("Invalid data window height value", err); |
| 6018 | return TINYEXR_ERROR_INVALID_DATA; |
| 6019 | } |
| 6020 | |
| 6021 | // Do not allow too large data_width and data_height. header invalid? |
| 6022 | { |
| 6023 | if (data_width > TINYEXR_DIMENSION_THRESHOLD) { |
| 6024 | tinyexr::SetErrorMessage("data width too large.", err); |
| 6025 | return TINYEXR_ERROR_INVALID_DATA; |
| 6026 | } |
| 6027 | if (data_height > TINYEXR_DIMENSION_THRESHOLD) { |
| 6028 | tinyexr::SetErrorMessage("data height too large.", err); |
| 6029 | return TINYEXR_ERROR_INVALID_DATA; |
| 6030 | } |
| 6031 | } |
no test coverage detected