prisma / tiberius

TDS 7.2+ (Microsoft SQL Server) driver for Rust
Apache License 2.0
321 stars 119 forks source link

Panic from try_get #211

Open Ankerbot opened 2 years ago

Ankerbot commented 2 years ago

https://github.com/prisma/tiberius/blob/0f3bffdbabc42233850682ff1767840edc9ccba4/src/row.rs#L392

Hey, thanks for tiberius!

In try_get in row.rs:390 there is the possibility to panic in the unwrap, which shouldn't happen.

I got it by doing


let stmt = "select 1";

let res = con.query(stmt, &[]).await?.into_first_result().await?;
let r = res.first().unwrap();

let a = r.try_get::<&str, _>(1)?;
dbg!(a);

I would expect it to return some kind of error instead of panic-ing, a generic one would be alright.

I feel like there is something else going wrong here, because normally the check for row bounds should have already returned an error.

grainednoise commented 2 years ago

It seems like the usize-impl for the QueryIndex trait does no checking, unlike the &str-impl. The lack of documentation for the QueryIndex trait makes it hard to judge if that would be the responsibility of said trait or not, but the current implementation seems inconsistent.

It would be easy enough to fix in the usize-impl for QueryIndex by checking against the length of row.columns.