| 8713 | } |
| 8714 | |
| 8715 | int ParseEXRMultipartHeaderFromMemory(EXRHeader ***exr_headers, |
| 8716 | int *num_headers, |
| 8717 | const EXRVersion *exr_version, |
| 8718 | const unsigned char *memory, size_t size, |
| 8719 | const char **err) { |
| 8720 | if (memory == NULL || exr_headers == NULL || num_headers == NULL || |
| 8721 | exr_version == NULL) { |
| 8722 | // Invalid argument |
| 8723 | tinyexr::SetErrorMessage( |
| 8724 | "Invalid argument for ParseEXRMultipartHeaderFromMemory", err); |
| 8725 | return TINYEXR_ERROR_INVALID_ARGUMENT; |
| 8726 | } |
| 8727 | |
| 8728 | if (size < tinyexr::kEXRVersionSize) { |
| 8729 | tinyexr::SetErrorMessage("Data size too short", err); |
| 8730 | return TINYEXR_ERROR_INVALID_DATA; |
| 8731 | } |
| 8732 | |
| 8733 | const unsigned char *marker = memory + tinyexr::kEXRVersionSize; |
| 8734 | size_t marker_size = size - tinyexr::kEXRVersionSize; |
| 8735 | |
| 8736 | std::vector<tinyexr::HeaderInfo> infos; |
| 8737 | |
| 8738 | for (;;) { |
| 8739 | tinyexr::HeaderInfo info; |
| 8740 | info.clear(); |
| 8741 | |
| 8742 | std::string err_str; |
| 8743 | bool empty_header = false; |
| 8744 | int ret = ParseEXRHeader(&info, &empty_header, exr_version, &err_str, |
| 8745 | marker, marker_size); |
| 8746 | |
| 8747 | if (ret != TINYEXR_SUCCESS) { |
| 8748 | |
| 8749 | // Free malloc-allocated memory here. |
| 8750 | for (size_t i = 0; i < info.attributes.size(); i++) { |
| 8751 | if (info.attributes[i].value) { |
| 8752 | free(info.attributes[i].value); |
| 8753 | } |
| 8754 | } |
| 8755 | |
| 8756 | tinyexr::SetErrorMessage(err_str, err); |
| 8757 | return ret; |
| 8758 | } |
| 8759 | |
| 8760 | if (empty_header) { |
| 8761 | marker += 1; // skip '\0' |
| 8762 | break; |
| 8763 | } |
| 8764 | |
| 8765 | // `chunkCount` must exist in the header. |
| 8766 | if (info.chunk_count == 0) { |
| 8767 | |
| 8768 | // Free malloc-allocated memory here. |
| 8769 | for (size_t i = 0; i < info.attributes.size(); i++) { |
| 8770 | if (info.attributes[i].value) { |
| 8771 | free(info.attributes[i].value); |
| 8772 | } |
no test coverage detected