| 5893 | } |
| 5894 | |
| 5895 | static int DecodeEXRImage(EXRImage *exr_image, const EXRHeader *exr_header, |
| 5896 | const unsigned char *head, |
| 5897 | const unsigned char *marker, const size_t size, |
| 5898 | const char **err) { |
| 5899 | if (exr_image == NULL || exr_header == NULL || head == NULL || |
| 5900 | marker == NULL || (size <= tinyexr::kEXRVersionSize)) { |
| 5901 | tinyexr::SetErrorMessage("Invalid argument for DecodeEXRImage().", err); |
| 5902 | return TINYEXR_ERROR_INVALID_ARGUMENT; |
| 5903 | } |
| 5904 | |
| 5905 | int num_scanline_blocks = 1; |
| 5906 | if (exr_header->compression_type == TINYEXR_COMPRESSIONTYPE_ZIP) { |
| 5907 | num_scanline_blocks = 16; |
| 5908 | } else if (exr_header->compression_type == TINYEXR_COMPRESSIONTYPE_PIZ) { |
| 5909 | num_scanline_blocks = 32; |
| 5910 | } else if (exr_header->compression_type == TINYEXR_COMPRESSIONTYPE_ZFP) { |
| 5911 | num_scanline_blocks = 16; |
| 5912 | } |
| 5913 | |
| 5914 | if (exr_header->data_window.max_x < exr_header->data_window.min_x || |
| 5915 | exr_header->data_window.max_x - exr_header->data_window.min_x == |
| 5916 | std::numeric_limits<int>::max()) { |
| 5917 | // Issue 63 |
| 5918 | tinyexr::SetErrorMessage("Invalid data width value", err); |
| 5919 | return TINYEXR_ERROR_INVALID_DATA; |
| 5920 | } |
| 5921 | tinyexr_int64 data_width = |
| 5922 | 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); |
| 5923 | if (data_width <= 0) { |
| 5924 | tinyexr::SetErrorMessage("Invalid data window width value", err); |
| 5925 | return TINYEXR_ERROR_INVALID_DATA; |
| 5926 | } |
| 5927 | |
| 5928 | if (exr_header->data_window.max_y < exr_header->data_window.min_y || |
| 5929 | exr_header->data_window.max_y - exr_header->data_window.min_y == |
| 5930 | std::numeric_limits<int>::max()) { |
| 5931 | tinyexr::SetErrorMessage("Invalid data height value", err); |
| 5932 | return TINYEXR_ERROR_INVALID_DATA; |
| 5933 | } |
| 5934 | tinyexr_int64 data_height = |
| 5935 | 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); |
| 5936 | |
| 5937 | if (data_height <= 0) { |
| 5938 | tinyexr::SetErrorMessage("Invalid data window height value", err); |
| 5939 | return TINYEXR_ERROR_INVALID_DATA; |
| 5940 | } |
| 5941 | |
| 5942 | // Do not allow too large data_width and data_height. header invalid? |
| 5943 | { |
| 5944 | if (data_width > TINYEXR_DIMENSION_THRESHOLD) { |
| 5945 | tinyexr::SetErrorMessage("data width too large.", err); |
| 5946 | return TINYEXR_ERROR_INVALID_DATA; |
| 5947 | } |
| 5948 | if (data_height > TINYEXR_DIMENSION_THRESHOLD) { |
| 5949 | tinyexr::SetErrorMessage("data height too large.", err); |
| 5950 | return TINYEXR_ERROR_INVALID_DATA; |
| 5951 | } |
| 5952 | } |
no test coverage detected