| 10244 | } |
| 10245 | |
| 10246 | int ParseEXRMultipartHeaderFromMemory(EXRHeader ***exr_headers, |
| 10247 | int *num_headers, |
| 10248 | const EXRVersion *exr_version, |
| 10249 | const unsigned char *memory, size_t size, |
| 10250 | const char **err) { |
| 10251 | if (memory == NULL || exr_headers == NULL || num_headers == NULL || |
| 10252 | exr_version == NULL) { |
| 10253 | // Invalid argument |
| 10254 | tinyexr::SetErrorMessage( |
| 10255 | "Invalid argument for ParseEXRMultipartHeaderFromMemory", err); |
| 10256 | return TINYEXR_ERROR_INVALID_ARGUMENT; |
| 10257 | } |
| 10258 | |
| 10259 | if (size < tinyexr::kEXRVersionSize) { |
| 10260 | tinyexr::SetErrorMessage("Data size too short", err); |
| 10261 | return TINYEXR_ERROR_INVALID_DATA; |
| 10262 | } |
| 10263 | |
| 10264 | const unsigned char *marker = memory + tinyexr::kEXRVersionSize; |
| 10265 | size_t marker_size = size - tinyexr::kEXRVersionSize; |
| 10266 | |
| 10267 | std::vector<tinyexr::HeaderInfo> infos; |
| 10268 | |
| 10269 | for (;;) { |
| 10270 | tinyexr::HeaderInfo info; |
| 10271 | info.clear(); |
| 10272 | |
| 10273 | std::string err_str; |
| 10274 | bool empty_header = false; |
| 10275 | int ret = ParseEXRHeader(&info, &empty_header, exr_version, &err_str, |
| 10276 | marker, marker_size); |
| 10277 | |
| 10278 | if (ret != TINYEXR_SUCCESS) { |
| 10279 | |
| 10280 | // Free malloc-allocated memory here. |
| 10281 | for (size_t i = 0; i < info.attributes.size(); i++) { |
| 10282 | if (info.attributes[i].value) { |
| 10283 | free(info.attributes[i].value); |
| 10284 | } |
| 10285 | } |
| 10286 | |
| 10287 | tinyexr::SetErrorMessage(err_str, err); |
| 10288 | return ret; |
| 10289 | } |
| 10290 | |
| 10291 | if (empty_header) { |
| 10292 | marker += 1; // skip '\0' |
| 10293 | break; |
| 10294 | } |
| 10295 | |
| 10296 | // `chunkCount` must exist in the header. |
| 10297 | if (info.chunk_count == 0) { |
| 10298 | |
| 10299 | // Free malloc-allocated memory here. |
| 10300 | for (size_t i = 0; i < info.attributes.size(); i++) { |
| 10301 | if (info.attributes[i].value) { |
| 10302 | free(info.attributes[i].value); |
| 10303 | } |
no test coverage detected