Skip to content

pg_catalog: properly handle zero when joining against pg_type on oid#58416

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
ajwerner:ajwerner/fix-questionable-descriptor
Jan 5, 2021
Merged

pg_catalog: properly handle zero when joining against pg_type on oid#58416
craig[bot] merged 1 commit intocockroachdb:masterfrom
ajwerner:ajwerner/fix-questionable-descriptor

Conversation

@ajwerner
Copy link
Copy Markdown
Contributor

@ajwerner ajwerner commented Jan 4, 2021

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 #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

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Member

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: thanks

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis and @lucy-zhang)

Copy link
Copy Markdown
Member

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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?

Copy link
Copy Markdown
Contributor Author

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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 GetTypeVersionByID just 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.

// UserDefinedTypeOIDToID converts a user defined type OID into a
// descriptor ID.
func UserDefinedTypeOIDToID(oid oid.Oid) descpb.ID {
return descpb.ID(oid) - oidext.CockroachPredefinedOIDMax
}

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.

@ajwerner ajwerner force-pushed the ajwerner/fix-questionable-descriptor branch from 258a664 to 21b0ac0 Compare January 4, 2021 15:00
Copy link
Copy Markdown
Contributor Author

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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 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.

// UserDefinedTypeOIDToID converts a user defined type OID into a
// descriptor ID.
func UserDefinedTypeOIDToID(oid oid.Oid) descpb.ID {
return descpb.ID(oid) - oidext.CockroachPredefinedOIDMax
}

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.

Updated.

Copy link
Copy Markdown
Member

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: 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
@ajwerner ajwerner force-pushed the ajwerner/fix-questionable-descriptor branch from 21b0ac0 to 5bb5460 Compare January 4, 2021 19:11
@ajwerner
Copy link
Copy Markdown
Contributor Author

ajwerner commented Jan 4, 2021

bors r=jordanlewis

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 4, 2021

Build failed:

@ajwerner
Copy link
Copy Markdown
Contributor Author

ajwerner commented Jan 4, 2021

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 5, 2021

Build succeeded:

@craig craig bot merged commit 8a55b49 into cockroachdb:master Jan 5, 2021
@rafiss rafiss added this to the 20.2 milestone Apr 22, 2021
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 this pull request may close these issues.

sql: found repro for "adding questionable descriptor 4294867296" sql: "refreshing descriptor: 4294867296" error from from uninitialized OID

4 participants