Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestamp and Duration generators render wrong number format for Java #781

Closed
lujiajing1126 opened this issue Jan 30, 2023 · 0 comments · Fixed by #782
Closed

Timestamp and Duration generators render wrong number format for Java #781

lujiajing1126 opened this issue Jan 30, 2023 · 0 comments · Fixed by #782

Comments

@lujiajing1126
Copy link
Contributor

lujiajing1126 commented Jan 30, 2023

In the envoyproxy protos, a large number is used in the duration validation rule,

// [#next-free-field: 8]
message DownstreamTlsContext {
// ...

  // If specified, ``session_timeout`` will change the maximum lifetime (in seconds) of the TLS session.
  // Currently this value is used as a hint for the `TLS session ticket lifetime (for TLSv1.2) <https://tools.ietf.org/html/rfc5077#section-5.6>`_.
  // Only seconds can be specified (fractional seconds are ignored).
  google.protobuf.Duration session_timeout = 6 [(validate.rules).duration = {
    lt {seconds: 4294967296}
    gte {}
  }];
}

Such use cases are also shown in the examples in the README.md in this repo.

But since the user-defined thresholds are possibly out of the bound of int32, i.e. the seconds field is int64 aka long in Java.

message Duration {
  // Signed seconds of the span of time. Must be from -315,576,000,000
  // to +315,576,000,000 inclusive. Note: these bounds are computed from:
  // 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
  int64 seconds = 1;

  // Signed fractions of a second at nanosecond resolution of the span
  // of time. Durations less than one second are represented with a 0
  // `seconds` field and a positive or negative `nanos` field. For durations
  // of one second or more, a non-zero value for the `nanos` field must be
  // of the same sign as the `seconds` field. Must be from -999,999,999
  // to +999,999,999 inclusive.
  int32 nanos = 2;
}

Compiling the proto file above will just cause exceptions, (with pgv 0.9.1)

image

The generated codes look like,

private final com.google.protobuf.Duration SESSION_TIMEOUT__LT = io.envoyproxy.pgv.TimestampValidation.toDuration(4294967296,0); // should be 4294967296L
private final com.google.protobuf.Duration SESSION_TIMEOUT__GTE = io.envoyproxy.pgv.TimestampValidation.toDuration(0,0);

I will submit a PR to resolve this issue.

elliotmjackson added a commit that referenced this issue Mar 20, 2023
Resolve #781

Co-authored-by: Elliot Jackson <13633636+elliotmjackson@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant