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

Poem crash during f64 parsing #883

Closed
rxdiscovery opened this issue Sep 12, 2024 · 3 comments
Closed

Poem crash during f64 parsing #883

rxdiscovery opened this issue Sep 12, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@rxdiscovery
Copy link

rxdiscovery commented Sep 12, 2024

Hello,

Recently, an application made with Poem crashed when sending JSON responses.

I investigated and found the cause:

thread 'tokio-runtime-worker' panicked at /home/XXXXX/.cargo/registry/src/index.crates.io-6f17d22XXXXXXX/poem-openapi-5.1.0/src/types/external/floats.rs:91:1:

It is this macro that is behind the exception :

impl_type_for_floats!((f32, "float"), (f64, "double"));

analyzing the code generated by this macro, I find the culprit:

       impl ToJSON for $ty {
            fn to_json(&self) -> Option<Value> {
                Some(Value::Number(Number::from_f64(*self as f64).unwrap())) //<----- UNWRAP <<<<
            }
        }

there's an “unwrap()” in the code (src/types/external/floats.rs), the exception is not handled.

In a post about a year ago, I pointed out the presence of several unwrap() functions in the Poem project source code. The unwrap() / except() functions should never be used in production code.

several files in src/types/external/ contain unwrap() :

  • array.rs
  • bson.rs
  • float.rs
  • time.rs

Thank you for all your efforts behind this framework. 👍

Specifications

  • Version: 3.1.0
@rxdiscovery rxdiscovery added the bug Something isn't working label Sep 12, 2024
@sunli829
Copy link
Collaborator

Thanks for the bug report, I fixed it except for array.rs. Since I checked the length, the try_into there couldn't possibly fail.

@sunli829
Copy link
Collaborator

released in v5.1.1

@rxdiscovery
Copy link
Author

@sunli829 Thank you very much for your responsiveness 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants