sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.42k stars 436 forks source link

Panic in Row::try_get #1072

Open conradludgate opened 10 months ago

conradludgate commented 10 months ago

I don't have a good explanation for what happened, but I see a panic in our production environment from the prepared statement code.

index out of bounds: the len is 1 but the index is 1

This panic comes from https://github.com/sfackler/rust-postgres/blob/c5ff8cfd86e897b7c197f52684a37a4f17cecb75/tokio-postgres/src/row.rs#L187 which in turn came from https://github.com/sfackler/rust-postgres/blob/c5ff8cfd86e897b7c197f52684a37a4f17cecb75/tokio-postgres/src/prepare.rs#L149

For some reason, the typeinfo query returned a row data entry with only a single item in it. I haven't yet searched any further to understand how this could possibly happen, but it did so I am reporting it. I plan to fix this in our fork by replacing ranges[idx] with ranges.get(idx)? but maybe there's a better solution (erroring on Row::new)?

sfackler commented 10 months ago

Very weird! Yeah, I think I'd prefer checking up front in Row::new.