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

Python protobuf should refuse to serialize Infinity and NaN #11259

Closed
ikonst opened this issue Dec 12, 2022 · 0 comments
Closed

Python protobuf should refuse to serialize Infinity and NaN #11259

ikonst opened this issue Dec 12, 2022 · 0 comments
Assignees
Labels

Comments

@ikonst
Copy link
Contributor

ikonst commented Dec 12, 2022

Since it doesn't roundtrip, we should refuse to serialize them, per docs:

Note that attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

Trying with protobuf 4.21.11:

import math

from google.protobuf import json_format, struct_pb2

inf_val = struct_pb2.Value(number_value=math.inf)
inf_json = json_format.MessageToJson(inf_val)
inf_val_roundtrip = json_format.Parse(inf_json, struct_pb2.Value())

print(inf_val)
print(inf_val_roundtrip)

outputs

number_value: inf
string_value: "Infinity"

See also golang/protobuf#1182

@ikonst ikonst added the untriaged auto added to all issues by default when created. label Dec 12, 2022
@anandolee anandolee self-assigned this Dec 14, 2022
@anandolee anandolee removed the untriaged auto added to all issues by default when created. label Dec 14, 2022
copybara-service bot pushed a commit that referenced this issue Dec 15, 2022
copybara-service bot pushed a commit that referenced this issue Dec 16, 2022
copybara-service bot pushed a commit that referenced this issue Dec 16, 2022
copybara-service bot pushed a commit that referenced this issue Jan 6, 2023
… format. fixes #11259

Implemented in java, c++, python and upb. Also added conformance test.

https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value
where it says:
attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

PiperOrigin-RevId: 496741357
copybara-service bot pushed a commit that referenced this issue Jan 6, 2023
… format. fixes #11259

Implemented in java, c++, python and upb. Also added conformance test.

https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value
where it says:
attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

PiperOrigin-RevId: 500139380
copybara-service bot pushed a commit that referenced this issue Jan 6, 2023
… format. fixes #11259

Implemented in java, c++, python and upb. Also added conformance test.

https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value
where it says:
attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

PiperOrigin-RevId: 500150934
copybara-service bot pushed a commit that referenced this issue Jan 7, 2023
… format. fixes #11259

Implemented in java, c++, python and upb. Also added conformance test.

https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value
where it says:
attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

PiperOrigin-RevId: 500150934
copybara-service bot pushed a commit that referenced this issue Jan 7, 2023
… format. fixes #11259

Implemented in java, c++, python and upb. Also added conformance test.

https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value
where it says:
attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

PiperOrigin-RevId: 500150934
copybara-service bot pushed a commit that referenced this issue Jan 9, 2023
… format. fixes #11259

Implemented in java, c++, python and upb. Also added conformance test.

https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value
where it says:
attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

PiperOrigin-RevId: 500150934
copybara-service bot pushed a commit that referenced this issue Jan 9, 2023
… format. fixes #11259

Implemented in java, c++, python and upb. Also added conformance test.

https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value
where it says:
attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

PiperOrigin-RevId: 500150934
copybara-service bot pushed a commit that referenced this issue Jan 9, 2023
… format. fixes #11259

Implemented in java, c++, python and upb. Also added conformance test.

https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value
where it says:
attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

PiperOrigin-RevId: 500150934
copybara-service bot pushed a commit that referenced this issue Jan 9, 2023
… format. fixes #11259

Implemented in java, c++, python and upb. Also added conformance test.

https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value
where it says:
attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

PiperOrigin-RevId: 500150934
copybara-service bot pushed a commit that referenced this issue Jan 9, 2023
… format. fixes #11259

Implemented in java, c++, python and upb. Also added conformance test.

https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value
where it says:
attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

PiperOrigin-RevId: 500828964
rinarakaki pushed a commit to rinarakaki/protobuf that referenced this issue Aug 30, 2023
… format. fixes protocolbuffers#11259

Implemented in java, c++, python and upb. Also added conformance test.

https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value
where it says:
attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

PiperOrigin-RevId: 500139380
rinarakaki pushed a commit to rinarakaki/protobuf that referenced this issue Aug 30, 2023
… format. fixes protocolbuffers#11259

Implemented in java, c++, python and upb. Also added conformance test.

https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value
where it says:
attempting to serialize NaN or Infinity results in error. (We can't serialize these as string "NaN" or "Infinity" values like we do for regular fields, because they would parse as string_value, not number_value).

PiperOrigin-RevId: 500828964
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment