Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix integer overflow bug in validation error message (#75)
## Symptom Some standard validation error messages have `Integer Overflow` bug on large decimal values. ## Example ```protobuf message LargeValue { uint64 count = 1 [(buf.validate.field).uint64 = {gte: 0, lte: 999999999999}]; } ``` ```java @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`](https://github.com/bufbuild/protovalidate-java/blob/b35a45f8eccb0aef7d5a0fdec20d0a4f159529f7/src/main/java/build/buf/protovalidate/internal/celext/Format.java#L101-L103): ```java // ... case 's': formatString(builder, arg); break; // ... ``` which eventually calls: ```java // ... } 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
- Loading branch information