rust-secure-code / safety-dance

Auditing crates for unsafe code which can be safely replaced
Apache License 2.0
536 stars 10 forks source link

Audit itoa #60

Open adetaylor opened 4 years ago

adetaylor commented 4 years ago

itoa has fast functions for printing integers. It's a dependency of serde_json so is included in lots of things. It's by the awesome dtolnay so I suspect it's unlikely we can add safety, but maybe we can identify patterns that can be better supported in future Rust.

https://github.com/dtolnay/itoa

adetaylor commented 4 years ago

Uses of unsafe:

Given the need to initialize the string from right to left for performance, the only options I see would be:

I wonder if the need for that latter type has shown up anywhere else in safety-dance's audits? Or if anyone has any better ideas?

Lokathor commented 4 years ago

If you only write byte values 0..=127 then it's impossible to not be valid utf8

Lokathor commented 4 years ago

and making a new buffer type for this would be pretty trivial since you only need push, not all general buffer methods