diff --git a/src/riffvideo.cpp b/src/riffvideo.cpp index 2b55ed281f..6ac5135220 100644 --- a/src/riffvideo.cpp +++ b/src/riffvideo.cpp @@ -648,14 +648,25 @@ void RiffVideo::StreamName(uint64_t size_) const { void RiffVideo::readInfoListChunk(uint64_t size_) { uint64_t current_size = DWORD; + + // Add the elements to a temporary table first, so that we can check + // for duplicates before adding them to xmpData_. + std::map table; while (current_size < size_) { std::string type = readStringTag(io_); size_t size = readDWORDTag(io_); std::string content = readStringTag(io_, size); - if (auto it = Internal::infoTags.find(type); it != Internal::infoTags.end()) - xmpData_[it->second] = content; + if (auto it = Internal::infoTags.find(type); it != Internal::infoTags.end()) { + // Check that it isn't a duplicate. + Internal::enforce(table.find(it->second) == table.end(), ErrorCode::kerCorruptedMetadata); + table[it->second] = content; + } current_size += DWORD * 2 + size; } + // Copy the elements from the temporary table to xmpData_. + for (const auto& it : table) { + xmpData_[it.first] = it.second; + } } void RiffVideo::readMoviList(uint64_t size_) const {