#MediaSequence Prevent undefined index access in metadata reconciliation.
Reconciliation required feature_lists.feature_list[0].value.feature[0].float_list.size_>=1, now we skip keys where size_=0. PiperOrigin-RevId: 508095655
This commit is contained in:
parent
19d895eb73
commit
4b28ced8fd
|
@ -160,6 +160,10 @@ absl::Status ReconcileMetadataFeatureFloats(
|
|||
const std::string& key = key_value.first;
|
||||
if (absl::StrContains(key, kFeatureFloatsKey)) {
|
||||
const auto prefix = key.substr(0, key.find(kFeatureFloatsKey) - 1);
|
||||
if (GetFeatureFloatsSize(prefix, *sequence) < 1) {
|
||||
// Unable to determine the feature dimensions as no data is provided.
|
||||
continue;
|
||||
}
|
||||
int number_of_elements = GetFeatureFloatsAt(prefix, *sequence, 0).size();
|
||||
if (HasFeatureDimensions(prefix, *sequence) &&
|
||||
!GetFeatureDimensions(prefix, *sequence).empty()) {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "mediapipe/framework/port/opencv_imgcodecs_inc.h"
|
||||
#include "mediapipe/framework/port/status_matchers.h"
|
||||
#include "tensorflow/core/example/example.pb.h"
|
||||
#include "tensorflow/core/example/feature.pb.h"
|
||||
|
||||
namespace mediapipe {
|
||||
namespace mediasequence {
|
||||
|
@ -867,6 +868,8 @@ TEST(MediaSequenceTest, ReconcileMetadataFloats) {
|
|||
AddFeatureFloats(feature_name, vf, &sequence);
|
||||
AddFeatureTimestamp(feature_name, 1000000, &sequence);
|
||||
AddFeatureTimestamp(feature_name, 2000000, &sequence);
|
||||
sequence.mutable_feature_lists()->mutable_feature_list()->insert(
|
||||
{"EMPTY/feature/floats", tensorflow::FeatureList()});
|
||||
|
||||
MP_ASSERT_OK(ReconcileMetadata(true, false, &sequence));
|
||||
ASSERT_EQ(GetFeatureDimensions(feature_name, sequence).size(), 1);
|
||||
|
|
Loading…
Reference in New Issue
Block a user