Skip to content

Commit 52b859c

Browse files
l46kokcopybara-github
authored andcommitted
Enforce bounds on explicit epoch to timestamp conversions
PiperOrigin-RevId: 845617691
1 parent 506c2b6 commit 52b859c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

common/src/main/java/dev/cel/common/internal/DateTimeHelpers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private static ZoneId timeZone(String tz) {
205205
}
206206

207207
/** Throws an {@link IllegalArgumentException} if the given {@link Timestamp} is not valid. */
208-
private static void checkValid(Instant instant) {
208+
public static void checkValid(Instant instant) {
209209
long seconds = instant.getEpochSecond();
210210

211211
if (seconds < TIMESTAMP_SECONDS_MIN || seconds > TIMESTAMP_SECONDS_MAX) {

runtime/src/main/java/dev/cel/runtime/standard/TimestampFunction.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ public enum TimestampOverload implements CelStandardOverload {
8181
(celOptions, runtimeEquality) -> {
8282
if (celOptions.evaluateCanonicalTypesToNativeValues()) {
8383
return CelFunctionBinding.from(
84-
"int64_to_timestamp", Long.class, Instant::ofEpochSecond);
84+
"int64_to_timestamp", Long.class, epochSecond -> {
85+
Instant instant = Instant.ofEpochSecond(epochSecond);
86+
DateTimeHelpers.checkValid(instant);
87+
return instant;
88+
});
8589
} else {
8690
return CelFunctionBinding.from(
8791
"int64_to_timestamp", Long.class, ProtoTimeUtils::fromSecondsToTimestamp);

0 commit comments

Comments
 (0)