[BUG] Validation of message with `com.google.protobuf.Timestamp` fails with `java.time.DateTimeException` if seconds/nanos exceed `Instant` bounds
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
從 src/main/java/build/buf/protovalidate/ProtoAdapter.java 中第 93-104 行附近的 scalarToCel 轉換開始,然後使用 seconds 值為 Long.MAX_VALUE 的 Timestamp 重現驗證。檢查 Timestamp 和 Duration 的極端值,並在驗證回傳明確的驗證錯誤而不是傳播日期或算術例外時,視為工作完成。
由索引模型根據 Issue 內容生成。
描述
Description
Validation of com.google.protobuf.Timestamp fails with java.time.DateTimeException when the timestamp's seconds or nanoseconds values exceed the bounds that can be represented by Java's Instant class. This occurs when attempting to validate protobuf messages containing timestamps with extreme values like Long.MAX_VALUE for seconds, which cannot be converted to a valid Instant object.
The underlying issue is in ProtoAdapter class:
Similar issue seems to also affect com.google.protobuf.Duration if using extreme nanos values due to the ProtoAdapter implementation linked above.
Steps to Reproduce
- Define a protobuf message with a
google.protobuf.Timestampfield:
syntax = "proto3";
package acme.foo.v1;
import "buf/validate/validate.proto";
message Foo {
google.protobuf.Timestamp bar = 1;
}
- Create a protobuf message instance with timestamp seconds set to
Long.MAX_VALUE:
Foo message = Foo.newBuilder()
.setBar(Timestamp.newBuilder().setSeconds(Long.MAX_VALUE))
.build();
- Attempt to validate the message using protovalidate:
ValidationResult result = validator.validate(message); - Observe the
java.time.DateTimeExceptionbeing thrown during validation
Expected Behavior
The validation should provide a clear validation error indicating the timestamp is out of bounds instead of throwing uncaught java.time.DateTimeException
Actual Behavior
A java.time.DateTimeException is thrown when the validator attempts to convert the protobuf timestamp to a Java Instant object, causing the entire validation process to fail with an unhandled exception rather than a proper validation error.
Screenshots/Logs
java.time.DateTimeException: Instant exceeds minimum or maximum instant
at java.base/java.time.Instant.create(Instant.java:414)
at java.base/java.time.Instant.ofEpochSecond(Instant.java:334)
at build.buf.protovalidate.ProtoAdapter.scalarToCel(ProtoAdapter.java:98)
at build.buf.protovalidate.ProtoAdapter.toCel(ProtoAdapter.java:65)
at build.buf.protovalidate.ObjectValue.value(ObjectValue.java:65)
at build.buf.protovalidate.ValueEvaluator.evaluate(ValueEvaluator.java:74)
at build.buf.protovalidate.FieldEvaluator.evaluate(FieldEvaluator.java:121)
at build.buf.protovalidate.MessageEvaluator.evaluate(MessageEvaluator.java:41)
Environment
- Protovalidate Version: v1.0.1
Possible Solution
The protovalidate ProtoAdapter class or some other part of logic before it should:
- Add bounds checking before attempting to convert protobuf timestamps to Java
Instantobjects or protobuf durations to JavaDurationobjects. - Or catch
DateTimeException(timestamp to Instant case) /ArithmeticException(duration case) during protobuf to Java instance conversion and convert it to a proper validation error
- 主要語言
- Java
- 星號
- 70
- 分支
- 18
- 平均合併
- 1 天 28 分鐘
- 30 天內合併 PR
- 11
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
bufbuild/protovalidate-java 的其他 Issue
-
難度 3/5 1-2 天 新手友好度 25/100
bufbuild/protovalidate-java#362 · 1 則留言 ·
維護者通常 1 天內回覆
-
[Feature Request] Extending protovalidate-java to other JVM Protobuf implementations可能重新可做 @pkwarren 於 1022 天前認領,目前沒有進行中的 PR。 未關閉Feature
bufbuild/protovalidate-java#80 · 已指派 1 人 ·
維護者通常 1 天內回覆
查看 bufbuild/protovalidate-java 的全部 Issue
相似的 Issue
-
Status: Pending Review Type: Feature Request
難度 1/5 1 小時以內 新手友好度 82/100
OpenRefine/OpenRefine#8019 ·
維護者通常 1 天內回覆
-
`timer` rule rejects dates the engine accepts可能已有人在做 @MFA-G 今天認領。 未關閉bug ready
難度 2/5 1-3 小時 新手友好度 72/100
camunda/bpmnlint-plugin-camunda-compat#281 · 3 則留言 ·
維護者通常 1 天內回覆
-
status: waiting-for-triage
難度 2/5 1-3 小時 新手友好度 72/100
-
bug
難度 2/5 1-3 小時 新手友好度 62/100
-
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆