[BUG] Validation of message with `com.google.protobuf.Timestamp` fails with `java.time.DateTimeException` if seconds/nanos exceed `Instant` bounds
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu tại src/main/java/build/buf/protovalidate/ProtoAdapter.java, xung quanh phần chuyển đổi scalarToCel ở các dòng 93-104, sau đó tái hiện việc validation với giá trị seconds của Timestamp là Long.MAX_VALUE. Kiểm tra cả các giá trị Timestamp và Duration cực trị, và coi công việc là hoàn tất khi validation trả về một validation error rõ ràng thay vì truyền tiếp một date hoặc arithmetic exception.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Java
- Star
- 70
- Fork
- 17
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 13
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bufbuild/protovalidate-java
-
1.0 update usage question Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
bufbuild/protovalidate-java#362 · 1 bình luận ·
-
Feature
bufbuild/protovalidate-java#80 · 1 người được giao ·
Tất cả issue của bufbuild/protovalidate-java
Issue tương tự
-
executions.Query — startDate and timeRange filters are sent with inverted comparison operators Đang mởarea/plugin
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
kestra-io/plugin-kestra#190 ·
-
litertlm-android AAR ships no consumer ProGuard rules → "mid == null" SIGABRT in minified apps Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Add canonical URLs and a sitemap Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
integra-team-red/meet-map#249 ·
-
[Studio][Bug] Cancelled create-user dialog keeps the password and admin switch for the next attempt Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
apache/rocketmq-dashboard#5064 ·