diff --git a/extensions/protobuf/internal/qualify.cc b/extensions/protobuf/internal/qualify.cc index 7c1503d1c..49de92621 100644 --- a/extensions/protobuf/internal/qualify.cc +++ b/extensions/protobuf/internal/qualify.cc @@ -14,6 +14,7 @@ #include "extensions/protobuf/internal/qualify.h" +#include #include #include @@ -290,13 +291,13 @@ absl::StatusOr ProtoQualifyState::CheckListIndex( cel::builtin::kIndex); } - int index = *qualifier.GetInt64Key(); + int64_t index = *qualifier.AsInt(); int size = reflection_->FieldSize(*message_, repeated_field_desc_); if (index < 0 || index >= size) { return absl::InvalidArgumentError( absl::StrCat("index out of bounds: index=", index, " size=", size)); } - return index; + return static_cast(index); } absl::Status ProtoQualifyState::ApplyAttributeQualifierList( diff --git a/extensions/select_optimization_test.cc b/extensions/select_optimization_test.cc index 227b902e8..7e15dc897 100644 --- a/extensions/select_optimization_test.cc +++ b/extensions/select_optimization_test.cc @@ -1301,6 +1301,23 @@ INSTANTIATE_TEST_SUITE_P( HasSubstr("index out of bounds"))); }, }, + { + // -2^32, which would read element 0 if truncated to an int. + "select_with_repeated_index_beyond_int32", + "nested_test_all_types.payload.repeated_nested_message" + "[-4294967296].bb", + {{"nested_test_all_types", + R"pb( + payload { repeated_nested_message {} } + )pb"}}, + ActivationSetupFn(), + [](const absl::StatusOr& got) { + ASSERT_OK_AND_ASSIGN(Value result, got); + ASSERT_TRUE(result->Is()) << result->DebugString(); + EXPECT_THAT(result.GetError().NativeValue(), + StatusIs(absl::StatusCode::kInvalidArgument)); + }, + }, { "unknown_field", "((false)? a.child.child : b.child).child.payload.single_int64",