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

protoc: parsing of float/double numeric values for options is inconsistent #15010

Closed
jhump opened this issue Dec 8, 2023 · 1 comment
Closed
Labels
enhancement inactive Denotes the issue/PR has not seen activity in the last 90 days. protoc

Comments

@jhump
Copy link
Contributor

jhump commented Dec 8, 2023

The parser has a special grammar for parsing default values that allows infinity, -infinity, and NaN. However, this grammar is not used when parsing other numeric option values.

Take the following example:

syntax = "proto2";

import "google/protobuf/descriptor.proto";

extend google.protobuf.MessageOptions {
  optional Foo foo = 10101;
}

message Foo {
  optional double val = 1 [default = -nan]; // "nan", "-nan", "inf", and "-inf" allowed here
  repeated float vals = 2;

  option (foo) = { val: -infINITY }; // aside: inside a message literal, anything goes 😭

  option (foo).vals = inf; // "nan", "-nan", "inf", and "-inf" NOT allowed here (??)
  // The above line results in the following error from protoc:
  //    test.proto:15:23: Value must be number for float option "Foo.vals".
  // If the value were -inf (negative), the message changes:
  //    test.proto:15:24: Invalid '-' symbol before identifier.
}

I assert that it's a bug that infinity and NaN can only be used in default values and not other option values. It seems like a simple overlooked thing that is easy to fix.

(As shown above, the contents of message literals, which are parsed using the text format, are very lenient. I'm certainly not suggesting that anything else in protoc should be that forgiving -- just pointing it out in the example since it's... interesting.)

@jhump jhump added the untriaged auto added to all issues by default when created. label Dec 8, 2023
@zhangskz zhangskz added enhancement protoc and removed untriaged auto added to all issues by default when created. labels Jan 19, 2024
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

@github-actions github-actions bot added the inactive Denotes the issue/PR has not seen activity in the last 90 days. label Apr 18, 2024
deannagarcia pushed a commit to deannagarcia/protobuf that referenced this issue Jun 20, 2024
…ffers#15017)

The parser already supports these values for the special "default" field option. But, inconsistently, does not support them for other options whose type is float or double. This addresses that inconsistency.

Fixes protocolbuffers#15010.

Closes protocolbuffers#15017

COPYBARA_INTEGRATE_REVIEW=protocolbuffers#15017 from jhump:jh/inf-and-nan-in-option-values 1f8217c
PiperOrigin-RevId: 627399259
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement inactive Denotes the issue/PR has not seen activity in the last 90 days. protoc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants