Skip to content

Commit 01826f5

Browse files
jnthntatumcopybara-github
authored andcommitted
Check for in-range timestamp and duration values in Value conversion.
PiperOrigin-RevId: 743645550
1 parent cff03a0 commit 01826f5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

conformance/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ cc_library(
2929
"//extensions/protobuf:value",
3030
"//internal:proto_time_encoding",
3131
"//internal:status_macros",
32+
"//internal:time",
3233
"@com_google_absl//absl/base:core_headers",
3334
"@com_google_absl//absl/base:nullability",
3435
"@com_google_absl//absl/status",
3536
"@com_google_absl//absl/status:statusor",
3637
"@com_google_absl//absl/strings",
3738
"@com_google_absl//absl/strings:cord",
39+
"@com_google_absl//absl/time",
3840
"@com_google_cel_spec//proto/cel/expr:checked_cc_proto",
3941
"@com_google_cel_spec//proto/cel/expr:syntax_cc_proto",
4042
"@com_google_cel_spec//proto/cel/expr:value_cc_proto",

conformance/value_conversion.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
#include "absl/status/statusor.h"
2626
#include "absl/strings/str_cat.h"
2727
#include "absl/strings/string_view.h"
28+
#include "absl/time/time.h"
2829
#include "common/any.h"
2930
#include "common/value.h"
3031
#include "common/value_kind.h"
3132
#include "extensions/protobuf/value.h"
3233
#include "internal/proto_time_encoding.h"
3334
#include "internal/status_macros.h"
35+
#include "internal/time.h"
3436
#include "google/protobuf/arena.h"
3537
#include "google/protobuf/descriptor.h"
3638
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
@@ -84,14 +86,18 @@ absl::StatusOr<Value> FromObject(
8486
if (!any.UnpackTo(&duration)) {
8587
return absl::InvalidArgumentError("invalid duration");
8688
}
87-
return cel::DurationValue(internal::DecodeDuration(duration));
89+
absl::Duration d = internal::DecodeDuration(duration);
90+
CEL_RETURN_IF_ERROR(cel::internal::ValidateDuration(d));
91+
return cel::DurationValue(d);
8892
} else if (any.type_url() ==
8993
"type.googleapis.com/google.protobuf.Timestamp") {
9094
google::protobuf::Timestamp timestamp;
9195
if (!any.UnpackTo(&timestamp)) {
9296
return absl::InvalidArgumentError("invalid timestamp");
9397
}
94-
return cel::TimestampValue(internal::DecodeTime(timestamp));
98+
absl::Time time = internal::DecodeTime(timestamp);
99+
CEL_RETURN_IF_ERROR(cel::internal::ValidateTimestamp(time));
100+
return cel::TimestampValue(time);
95101
}
96102

97103
return extensions::ProtoMessageToValue(any, descriptor_pool, message_factory,

0 commit comments

Comments
 (0)