Skip to content

Handling overflows/underflows for integer numbers in ProtoJSON #24772

@pananton13

Description

@pananton13

Hello! Looks like official ProtoJSON documentation is lying or may be I'm misunderstanding it (from here https://protobuf.dev/programming-guides/json/#out-of-range-numeric-values):

Out of range numeric values
When parsing a numeric value, if the number that is is parsed from the wire doesn’t fit in the corresponding type, the parser should coerce the value to the appropriate type. This has the same behavior as a simple cast in C++ or Java (for example, if a number larger than 2^32 is read as for an int32 field, it will be truncated to 32 bits).

However, looking into the code it looks like json parser will signal error instead of silently casting to a smaller-sized int https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/json/internal/parser.cc#L240 .

Can u please comment this?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions