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