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

fix(convert): return error when conversion exceeds f64 bounds #1108

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

dhable
Copy link
Contributor

@dhable dhable commented Nov 1, 2024

Prior to this commit, string values that would exceed the f64 bounds would return f64::INFINITY. This leaks a type into the VRL scripts that could cause a panic without support to check for the value.

Fixes #1107

Summary

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

How did you test this PR?

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on
    our guidelines.
  • No. A maintainer will apply the "no-changelog" label to this PR.

Checklist

  • Our CONTRIBUTING.md is a good starting place.
  • If this PR introduces changes to LICENSE-3rdparty.csv, please
    run dd-rust-license-tool write and commit the changes. More details here.
  • For new VRL functions, please also create a sibling PR in Vector to document the new function.

References

Copy link
Member

@pront pront left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dhable, left a couple of comments but this change makes sense to me.

Outside of this PR, I will take a look into the to_float vs parse_float implementations for string arguments.

@@ -0,0 +1,2 @@
Fixes the `to_float` function to return an error instead of "infinity" when parsing a string outside
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace fix in the file name with breaking.

@@ -159,6 +159,11 @@ impl Conversion {
let parsed = s
.parse::<f64>()
.with_context(|_| FloatParseSnafu { s: s.clone() })?;
if parsed.is_infinite() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite nuanced, but I think the least surprising behavior is to use https://doc.rust-lang.org/std/primitive.f64.html#method.is_normal here.

@pront
Copy link
Member

pront commented Nov 12, 2024

Hi @dhable, thank you for this contribution. Do you plan to drive this PR to completion? Let me know if I can help.

@dhable
Copy link
Contributor Author

dhable commented Nov 12, 2024

@pront Yes, I just got back from PTO but I'll get the suggestions added.

Copy link
Member

@pront pront left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @dhable. Left a couple of suggestions.

changelog.d/1107.breaking.md Outdated Show resolved Hide resolved
src/compiler/conversion/mod.rs Outdated Show resolved Hide resolved
Prior to this commit, string values that would exceed the f64 bounds would
return `f64::INFINITY`. This leaks a type into the VRL scripts that could
cause a panic without support to check for the value.

Fixes vectordotdev#1107

Co-authored-by: Pavlos Rontidis <pavlos.rontidis@gmail.com>
@pront pront enabled auto-merge November 13, 2024 16:28
@pront pront added this pull request to the merge queue Nov 13, 2024
Merged via the queue into vectordotdev:main with commit 2ee31a4 Nov 13, 2024
14 checks passed
pront added a commit that referenced this pull request Dec 6, 2024
github-merge-queue bot pushed a commit that referenced this pull request Dec 6, 2024
…64 bounds" (#1179)

* Revert "fix(convert): return error when conversion exceeds f64 bounds (#1108)"

This reverts commit 2ee31a4.

* add changelog
pront added a commit that referenced this pull request Dec 9, 2024
…64 bounds" (#1179)

* Revert "fix(convert): return error when conversion exceeds f64 bounds (#1108)"

This reverts commit 2ee31a4.

* add changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

to_float and infinity result can crash vector
2 participants