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 Type<Postgres> from u32 #1478

Closed
demurgos opened this issue Oct 7, 2021 · 2 comments · Fixed by #1602
Closed

Remove Type<Postgres> from u32 #1478

demurgos opened this issue Oct 7, 2021 · 2 comments · Fixed by #1602

Comments

@demurgos
Copy link
Contributor

demurgos commented Oct 7, 2021

Sqlx currently implements Type<Postgres> on the u32 primitive (and related types):

impl Type<Postgres> for u32 {

This is used as a shorthand when interacting with raw OIDs, but causes issues with regular code. Postgres does not support unsigned integers natively, but because of this impl it is easy to pass a u32 accidentally when binding values.

This is not a theorical footgun: it occurs to me every few months to get bitten by this.
Most recently, I had a bunch of code expecting a INT8 CHECK (VALUE >= 0) but forgot to use i64::from(some_input_u32) and managed to get a memory corruption on Postgres (because of unexpected argument buffer sizes).

The solution is simple: define an Oid(u32) wrapper type and implement the type-related traits on Oid instead of u32. It would make it more explicit when using a Oid and prevent these kinds of errors when using a bare u32.

EDIT: This is a breaking change, but could be part of the 6.0 0.6.0 release.

@jplatte
Copy link
Contributor

jplatte commented Oct 7, 2021

Nitpick: The next release will be 0.6.0, not 6.0 😉

@paolobarbolini
Copy link
Contributor

I've opened #1602 to try to get this fixed

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 a pull request may close this issue.

3 participants