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

Fix integer overflow bug in validation error message #75

Merged
merged 2 commits into from
Dec 19, 2023

Conversation

lyang
Copy link
Contributor

@lyang lyang commented Dec 18, 2023

Symptom

Some standard validation error messages have Integer Overflow bug on large decimal values.

Example

message LargeValue {
  uint64 count = 1 [(buf.validate.field).uint64 = {gte: 0, lte: 999999999999}];
}
@Test
public void validate_count() {
  LargeValue value = LargeValue.newBuilder().setCount(9999999999999).build();
  ValidationResult result = new Validator().validate(value);
  assertThat(result.getViolations().get(0).getMessage()).isEqualTo("value must be greater than or equal to 0 and less than or equal to 999999999999");
  // Above fails with: "value must be greater than or equal to 0 and less than or equal to -727379969"
}

Cause

This is due to %s interpreted as String in Format.java:

// ...
        case 's':
          formatString(builder, arg);
          break;
// ...

which eventually calls:

// ...
    } else if (type == TypeEnum.Int || type == TypeEnum.Uint) {
      formatInteger(builder, Long.valueOf(val.intValue()).intValue());
// ...

Note

Originally fixed in a different way in bufbuild/protovalidate#144

@nicksnyder nicksnyder requested a review from pkwarren December 18, 2023 23:18
@pkwarren pkwarren merged commit 581067b into bufbuild:main Dec 19, 2023
4 checks passed
@lyang
Copy link
Contributor Author

lyang commented Dec 21, 2023

Hi,
Just want to check in and see if there's a release scheduled soon?

Thanks!

@nicksnyder
Copy link
Member

Just released 0.1.9

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 this pull request may close these issues.

3 participants