[BUG] Validation of message with `com.google.protobuf.Timestamp` fails with `java.time.DateTimeException` if seconds/nanos exceed `Instant` bounds
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 45/100
Línea de trabajo
Comience en src/main/java/build/buf/protovalidate/ProtoAdapter.java, alrededor de la conversión scalarToCel en las líneas 93-104, y después reproduzca la validación con un valor de segundos de Timestamp igual a Long.MAX_VALUE. Compruebe tanto los valores extremos de Timestamp como de Duration, y considere el trabajo completo cuando la validación devuelva un error de validación claro en lugar de propagar una excepción de fecha o aritmética.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Java
- Estrellas
- 70
- Forks
- 17
- Merge medio
- 2 d 13 h
- PR fusionados (30 d)
- 13
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de bufbuild/protovalidate-java
-
1.0 update usage question Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 25/100
bufbuild/protovalidate-java#362 · 1 comentario ·
-
Feature
bufbuild/protovalidate-java#80 · 1 asignado ·
Todos los issues de bufbuild/protovalidate-java
Issues similares
-
executions.Query — startDate and timeRange filters are sent with inverted comparison operators Abiertoarea/plugin
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
kestra-io/plugin-kestra#190 ·
-
litertlm-android AAR ships no consumer ProGuard rules → "mid == null" SIGABRT in minified apps Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Add canonical URLs and a sitemap Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
integra-team-red/meet-map#249 ·
-
[Studio][Bug] Cancelled create-user dialog keeps the password and admin switch for the next attempt Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
apache/rocketmq-dashboard#5064 ·