Skip to content

Commit a6bdd0a

Browse files
Add conformance test cases for malformed nanos fields on Durations and Timestamps.
Durations have a validity restriction on `nanos` that: - The range allowed is (-1s..1s) exclusive - The sign must match the sign of `secs` (for 0 secs both positive and negative values of nanos are allowed) Timestamps have a validity restriction on `nanos` that: - The range allowed is [0..1s) These cases have always been commented as only being valid under these constraints, and other validity constraints are already checked to be handled as ProtoJSON serialize-failures, but this particular condition was not covered by the conformance suite. PiperOrigin-RevId: 791194939
1 parent fbe1d65 commit a6bdd0a

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

conformance/binary_json_conformance_suite.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,6 +3128,18 @@ void BinaryAndJsonConformanceSuiteImpl<
31283128
"DurationProtoInputTooLarge", REQUIRED,
31293129
"optional_duration: {seconds: 315576000001 nanos: 0}");
31303130

3131+
ExpectSerializeFailureForJson("DurationProtoNanosWrongSign", REQUIRED,
3132+
"optional_duration: {seconds: 1 nanos: -1}");
3133+
ExpectSerializeFailureForJson("DurationProtoNanosWrongSignNegativeSecs",
3134+
REQUIRED,
3135+
"optional_duration: {seconds: -1 nanos: 1}");
3136+
ExpectSerializeFailureForJson(
3137+
"DurationProtoNanosTooSmall", REQUIRED,
3138+
"optional_duration: {seconds: -1 nanos: -1000000000}");
3139+
ExpectSerializeFailureForJson(
3140+
"DurationProtoNanosTooLarge", REQUIRED,
3141+
"optional_duration: {seconds: 1 nanos: 1000000000}");
3142+
31313143
RunValidJsonTestWithValidator(
31323144
"DurationHasZeroFractionalDigit", RECOMMENDED,
31333145
R"({"optionalDuration": "1.000000000s"})", [](const Json::Value& value) {
@@ -3220,6 +3232,12 @@ void BinaryAndJsonConformanceSuiteImpl<
32203232
"optional_timestamp: {seconds: -62135596801}");
32213233
ExpectSerializeFailureForJson("TimestampProtoInputTooLarge", REQUIRED,
32223234
"optional_timestamp: {seconds: 253402300800}");
3235+
ExpectSerializeFailureForJson(
3236+
"TimestampProtoNegativeNanos", REQUIRED,
3237+
"optional_timestamp: {seconds: 5000 nanos: -1}");
3238+
ExpectSerializeFailureForJson(
3239+
"TimestampProtoNanoTooLarge", REQUIRED,
3240+
"optional_timestamp: {seconds: 5000 nanos: 1000000000}");
32233241
RunValidJsonTestWithValidator(
32243242
"TimestampZeroNormalized", RECOMMENDED,
32253243
R"({"optionalTimestamp": "1969-12-31T16:00:00-08:00"})",

conformance/failure_list_cpp.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ Recommended.*.FieldMaskNumbersDontRoundTrip.JsonOutput
3333
Recommended.*.FieldMaskPathsDontRoundTrip.JsonOutput # Should have failed to serialize, but didn't.
3434
Recommended.*.FieldMaskTooManyUnderscore.JsonOutput # Should have failed to serialize, but didn't.
3535
Recommended.*.JsonInput.FieldMaskInvalidCharacter # Should have failed to parse, but didn't.
36+
Required.*.TimestampProtoNanoTooLarge.JsonOutput # Should have failed to serialize, but didn't.
37+
Required.*.TimestampProtoNegativeNanos.JsonOutput # Should have failed to serialize, but didn't.

conformance/failure_list_php.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ Required.*.JsonInput.AnyWithNoType.*
3838
Required.*.JsonInput.TimestampWithMissingColonInOffset # Should have failed to parse, but didn't.
3939
Required.Editions_Proto3.JsonInput.DoubleFieldTooLarge # Should have failed to parse, but didn't.
4040
Required.Proto3.JsonInput.DoubleFieldTooLarge # Should have failed to parse, but didn't.
41+
Required.*.DurationProtoNanosTooLarge.JsonOutput # Should have failed to serialize, but didn't.
42+
Required.*.DurationProtoNanosTooSmall.JsonOutput # Should have failed to serialize, but didn't.
43+
Required.*.DurationProtoNanosWrongSign.JsonOutput # Should have failed to serialize, but didn't.
44+
Required.*.DurationProtoNanosWrongSignNegativeSecs.JsonOutput # Should have failed to serialize, but didn't.
45+
Required.*.TimestampProtoNanoTooLarge.JsonOutput # Should have failed to serialize, but didn't.
46+
Required.*.TimestampProtoNegativeNanos.JsonOutput # Should have failed to serialize, but didn't.

0 commit comments

Comments
 (0)