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

Remove dependency on lexical #337

Closed
BatmanAoD opened this issue Feb 5, 2024 · 1 comment · Fixed by #400
Closed

Remove dependency on lexical #337

BatmanAoD opened this issue Feb 5, 2024 · 1 comment · Fixed by #400

Comments

@BatmanAoD
Copy link
Contributor

There are soundness issues in the lexical crate. This warning from deny includes explanations of the soundness issues and recommendations for how to get similar functionality without the lexical crate.

From a brief look at the code, it appears that we only use the lexical crate to format floating-point numbers; however, the deny recommendation does not recommend anything for this use-case. One crate that may provide what we need is numfmt.

warning[unsound]: Multiple soundness issues

   ┌─ /github/workspace/Cargo.lock:70:1
   │
70 │ lexical 6.1.1 registry+https://github.com/rust-lang/crates.io-index
   │ ------------------------------------------------------------------- unsound advisory detected
   │

= ID: RUSTSEC-2023-0055
= Advisory: https://rustsec.org/advisories/RUSTSEC-2023-0055
= lexical contains multiple soundness issues:

  1. Bytes::read() allows creating instances of types with invalid bit patterns
  2. BytesIter::read() advances iterators out of bounds
  3. The BytesIter trait has safety invariants but is public and not marked unsafe
  4. write_float() calls MaybeUninit::assume_init() on uninitialized data, which is is not allowed by the Rust abstract machine

The crate also has some correctness issues and appears to be unmaintained.

Alternatives

For quickly parsing floating-point numbers third-party crates are no longer needed. A fast float parsing algorith by the author of lexical has been merged into libcore.

For quickly parsing integers, consider atoi and btoi crates (100% safe code). atoi_radix10 provides even faster parsing, but only with -C target-cpu=native, and at the cost of some unsafe.

For formatting integers in a #[no_std] context consider the numtoa crate.

For working with big numbers consider num-bigint and num-traits.

@Shadow53
Copy link
Contributor

Shadow53 commented Aug 9, 2024

For more context, this appears to be the only function that uses lexical, so it should be fairly straightforward to replace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants