Skip to content

Commit

Permalink
infoschema: fix panic for TableByID when table id is negative
Browse files Browse the repository at this point in the history
  • Loading branch information
lcwangchao committed Mar 22, 2024
1 parent 985d7da commit 2af6a4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/infoschema/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,8 +969,11 @@ func NewBuilder(r autoid.Requirement, factory func() (pools.Resource, error), in
}
}

func tableBucketIdx(tableID int64) int {
return int(tableID % bucketCount)
func tableBucketIdx(tableID int64) (idx int) {
if idx = int(tableID % bucketCount); idx < 0 {
idx = -idx
}
return
}

func tableIDIsValid(tableID int64) bool {
Expand Down
4 changes: 4 additions & 0 deletions pkg/infoschema/infoschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ func TestBasic(t *testing.T) {
require.False(t, ok)
require.Nil(t, tb)

tb, ok = is.TableByID(-12345)
require.False(t, ok)
require.Nil(t, tb)

tb, err = is.TableByName(dbName, tbName)
require.NoError(t, err)
require.NotNil(t, tb)
Expand Down

0 comments on commit 2af6a4e

Please sign in to comment.