pg_catalog: properly handle zero when joining against pg_type on oid#58416
Conversation
20cbd2f to
258a664
Compare
jordanlewis
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis and @lucy-zhang)
jordanlewis
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @ajwerner, @jordanlewis, and @lucy-zhang)
pkg/sql/pg_catalog.go, line 2416 at r1 (raw file):
return false, nil } if pgerror.GetPGCode(err) == pgcode.UndefinedObject {
Actually, should we just fall through to this case? Shouldn't GetTypeVersionByID just fail if it gets a 0 as normal?
ajwerner
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis and @lucy-zhang)
pkg/sql/pg_catalog.go, line 2416 at r1 (raw file):
Previously, jordanlewis (Jordan Lewis) wrote…
Actually, should we just fall through to this case? Shouldn't
GetTypeVersionByIDjust fail if it gets a 0 as normal?
Maybe but honestly I'd prefer that we never lookup 0 which is specifically the constant descpb.InvalidDescriptorID. The thing here isn't that id is 0 but that it's 0 - 100000 which wraps around.
cockroach/pkg/sql/catalog/typedesc/type_desc.go
Lines 148 to 152 in 448663c
My feeling is that typedesc.UserDefinedTypeOIDToID should be panicking here if ooid is less than 100000. I'm inclined to do something like above the id := ...:
if ooid < oidext.CockroachPredefinedOIDMax {
return false, nil
}We can't assert because users can provide arbitary values for this join. I'm going to do that instead.
258a664 to
21b0ac0
Compare
ajwerner
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @jordanlewis and @lucy-zhang)
pkg/sql/pg_catalog.go, line 2416 at r1 (raw file):
Previously, ajwerner wrote…
Maybe but honestly I'd prefer that we never lookup
0which is specifically the constantdescpb.InvalidDescriptorID. The thing here isn't thatidis0but that it's0 - 100000which wraps around.cockroach/pkg/sql/catalog/typedesc/type_desc.go
Lines 148 to 152 in 448663c
My feeling is that
typedesc.UserDefinedTypeOIDToIDshould be panicking here ifooidis less than100000. I'm inclined to do something like above theid := ...:if ooid < oidext.CockroachPredefinedOIDMax { return false, nil }We can't assert because users can provide arbitary values for this join. I'm going to do that instead.
Updated.
jordanlewis
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis and @lucy-zhang)
Zero is used in the `typelem` field of `pg_type` when not referring to anything. We currently end up treating `0` like a bogus user-defined type (see cockroachdb#58414). This commit detects zero and avoids this bad behavior. I want to backport this change but I don't really know how to describe its impact beyond elimating an alarming log message. Fixes cockroachdb#57868. Fixes cockroachdb#55290. Release note: None
21b0ac0 to
5bb5460
Compare
|
bors r=jordanlewis |
|
Build failed: |
|
bors r+ |
|
Build succeeded: |
Zero is used in the
typelemfield ofpg_typewhen not referring toanything. We currently end up treating
0like a bogus user-defined type(see #58414). This commit detects zero and avoids this bad behavior.
I want to backport this change but I don't really know how to describe
its impact beyond eliminating an alarming log message.
Fixes #57868.
Fixes #55290.
Release note: None