-
Notifications
You must be signed in to change notification settings - Fork 18k
database/sql: possible new panic doing reflect-based conversions #46730
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
Comments
Why does TL;DR: My 2c for (a) |
Perhaps we should add in package reflect |
I agree with @tgulacsi, the package already handles reflect panics, so I'd vote for |
@ianlancetaylor that's a great idea. We aren't going to be the only ones having to figure out how to work around this. Is there time yet to do that for 1.17? Does it need to go through the proposal process? |
Note that adding Value-based ConvertibleTo and Comparable will effectively implement choice (c) above, which is in conflict with what appears to be a broad preference for choice (a). |
Aren't the Kinds different (array & slice) so that sv.Convert() never gets called? |
I filed #46746. |
That said I agree with @renthraysk that I don't see a problem with the current code due to the explicit |
That's embarassing; I combed through all the code above it and failed to read the very code I copy/pasted. Thanks, @renthraysk. Everything remaining to do here is in #46746 (thanks, Ian!). |
Go 1.17 adds conversions from
[]T
to*[N]T
, including via the reflect package. Such conversions may panic if N is larger than the slice length. Whether reflection-based conversion is possible without panicking is thus now no longer a function only of the types involved. As a result, even ifv.Type().ConvertibleTo(w.Type())
returns true,v.Convert(w.Type())
may panic. This is documented in package reflect.database/sql/convert.go contains code that appears to rely on that now-broken invariant:
(text/template has similar code, but it is guarded with a check that the types are int-like.)
This
sv.Convert
call couldn't panic in 1.16; now it can.What should we do here?
(a) seems like the clearest error output. (b) is simple. It also matches the handling in the standard library of reflect.Type.Comparable: In a few places, we check reflect.Type.Comparable and then blindly use
==
, even though that can panic. (c) most closely preserves the 1.16 behavior.I lean towards (a) but would like to discuss. And if we do (a) or (c), should we give reflect.Type.Comparable/
==
the same treatment?Marking as a 1.17 release-blocker, pending a decision about severity and how we want to proceed.
cc @dsnet @ianlancetaylor @mdempsky @OneOfOne
The text was updated successfully, but these errors were encountered: