upb JSON nanos: distinguish Timestamp -1 from valid negative Duration values
The same nanos field has different allowed ranges depending on message type.
Different typed rules for the same field
The same nanos field has different allowed ranges depending on message type. Check typed range and sign obligations before encoding. Preserve message kind in Truthound inputs; rejecting every negative or admitting all of them would damage a different type’s valid records. [1, 2, 3]
The scope established by the overflow report
Protobuf #31032 reports an upb Duration encode overflow at nanos=-2147483648 under UBSan and missing range rejection for Timestamp nanos=-1. Its local patch and threat-model discussion are not a certification of security or the same execution result in every language binding. [1]
Inspect raw components before formatting
Show raw seconds and nanos for Duration and Timestamp, withholding JSON export approval for values outside the relevant type’s range. Extract integer components safely before formatting, and record the Duration sign-agreement rule separately instead of inferring components from an exported string. [1, 3]
Expected rejection of Timestamp -1
The illustrative Timestamp has seconds=0,nanos=-1, outside its 0~999999999 nanos range. Expected admission is 0; observed 0 meets the rejection condition and 1 fails. Duration permits nanos down to -999999999, so applying Timestamp’s lower bound 0 to Duration would discard valid negatives. [1, 3]
An admission table prepared safely
Truthound Core Python SDK 3.3.2 can compare prepared typed_range_admission and actual_admission using ColumnPairValidator with relationship="==". The operator supplies non-missing policy flags from message kind and safely extracted raw integers. The SDK does not repair C encoder overflow or certify memory safety of input decoding. [1, 2, 3]
Typed ranges that preserve valid negatives
Use a verified encoder correction and typed boundary tests, returning invalid input through an explicit error path. Duration’s -999999999999999999 range differs from Timestamp’s 0999999999 range. Passing nanos admission does not establish seconds bounds or all sign obligations. [1, 3]
Application conditions
Preserve integer nanos and message kind before conversion, checking Duration seconds/nanos sign agreement separately.
Alternatives
Use a verified encoder correction with typed boundary tests and an explicit invalid-input error path.
Limitations
The SDK does not repair C overflow or certify security; admission checks require safely extracted raw components.
Evidence
- Event checked
- Subject checked
- Modified
