rowcodec: fix panic when encode MaxUint16 len data (#15404)

This commit is contained in:
lysu
2020-03-16 20:20:53 +08:00
committed by GitHub
parent af861eeba2
commit 86a148bdee
2 changed files with 23 additions and 15 deletions

View File

@ -152,21 +152,6 @@ func (encoder *Encoder) encodeRowCols(sc *stmtctx.StatementContext, numCols, not
r.offsets[i] = uint16(len(r.data))
}
}
// handle convert to large
if !r.large {
if len(r.data) >= math.MaxUint16 {
r.large = true
r.initColIDs32()
for i, val := range r.colIDs {
r.colIDs32[i] = uint32(val)
}
} else {
r.initOffsets()
for i, val := range r.offsets32 {
r.offsets[i] = uint16(val)
}
}
}
return nil
}

View File

@ -753,6 +753,29 @@ func (s *testSuite) TestOldRowCodec(c *C) {
}
}
func (s *testSuite) Test65535Bug(c *C) {
colIds := []int64{1}
tps := make([]*types.FieldType, 1)
tps[0] = types.NewFieldType(mysql.TypeString)
sc := new(stmtctx.StatementContext)
text65535 := strings.Repeat("a", 65535)
encode := rowcodec.Encoder{}
bd, err := encode.Encode(sc, colIds, []types.Datum{types.NewStringDatum(text65535)}, nil)
c.Check(err, IsNil)
cols := make([]rowcodec.ColInfo, 1)
cols[0] = rowcodec.ColInfo{
ID: 1,
Tp: int32(tps[0].Tp),
Flag: int32(tps[0].Flag),
}
dc := rowcodec.NewDatumMapDecoder(cols, -1, nil)
result, err := dc.DecodeToDatumMap(bd, -1, nil)
c.Check(err, IsNil)
rs := result[1]
c.Check(rs.GetString(), Equals, text65535)
}
var (
withUnsigned = func(ft *types.FieldType) *types.FieldType {
ft.Flag = ft.Flag | mysql.UnsignedFlag