driver-go icon indicating copy to clipboard operation
driver-go copied to clipboard

runtime error: makeslice: len out of range

Open lw-leo opened this issue 2 years ago • 2 comments

数据量比较大时,查询数据时报错

panic({0xe79ae0, 0x114af40}) /go/src/runtime/panic.go:844 +0x258 github.com/taosdata/driver-go/v3/common/parser.rawConvertBinary(0xe71560?, 0xc000422270?, 0x7fb3220c8130?) /go/pkg/mod/github.com/taosdata/driver-go/[email protected]/common/parser/block.go:200 +0x59 github.com/taosdata/driver-go/v3/common/parser.ReadRow({0xc0003e0140, 0x13, 0xc0003e0140?}, 0x7fb2f005f4d5, 0x64, 0x0, {0xc001888c78, 0x13, 0xe75820?}, 0x0) /go/pkg/mod/github.com/taosdata/driver-go/[email protected]/common/parser/block.go:291 +0x14b github.com/taosdata/driver-go/v3/taosSql.(*rows).Next(0xc001424ae0, {0xc0003e0140, 0x13, 0x13}) /go/pkg/mod/github.com/taosdata/driver-go/[email protected]/taosSql/rows.go:79 +0x165

lw-leo avatar Sep 08 '23 06:09 lw-leo

请提供复现代码

sangshuduo avatar Sep 10 '23 14:09 sangshuduo

golang client driver

version:

  • github.com/taosdata/driver-go/v3 v3.5.0

varchar 字段能存,但是 client driver 不能读,driver panic, int16 越界长度报错


  • 复现方式: td sql

     `sql CREATE STABLE `super_for_test` (`ts` TIMESTAMP, `json_value` VARCHAR(40000)) TAGS (`dev_id` VARCHAR(50));`
    
    INSERT INTO 'super_for_test_123' USING 'super_for_test'
    TAGS ('123')
    ('ts', 'json_value')
        VALUES (1704881588040,
    {{字符串len > int16}}
    );
    
  • golang clinet

func TestTDPanic(t *testing.T) {
    type Tmp struct {
        Ts      time.Time `json:"ts" db:"ts"` 
        JsonStr string    `json:"json_str" db:"json_value"`
    }
    rows, err := Ddata.td.Query("select ts, json_value from super_for_test")
    require.NoError(t, err)
    for rows.Next() {
        r := &Tmp{}
        var ts time.Time
        err = rows.Scan(&ts, &r.JsonStr)
        if err != nil {
            require.NoError(t, err)
        }
        fmt.Println(r)
    }

    //--- FAIL: TestTDPanic (0.07s)
    //panic: runtime error: makeslice: len out of range [recovered]
    // panic: runtime error: makeslice: len out of range
}
  • panic 位置

github.com/taosdata/driver-go/[email protected]/common/parser/block.go:200

func rawConvertBinary(pHeader, pStart uintptr, row int) driver.Value {
	offset := *((*int32)(unsafe.Pointer(pHeader + uintptr(row*4))))
	if offset == -1 {
		return nil
	}
	currentRow := unsafe.Pointer(pStart + uintptr(offset))
	clen := *((*int16)(currentRow))
	currentRow = unsafe.Pointer(uintptr(currentRow) + 2)
	println("**********: %v", clen)
	binaryVal := make([]byte, clen)

	for index := int16(0); index < clen; index++ {
		binaryVal[index] = *((*byte)(unsafe.Pointer(uintptr(currentRow) + uintptr(index))))
	}
	return string(binaryVal[:])
}

output:
**********: %v -32767

@sangshuduo

fengtongxue avatar Feb 27 '24 10:02 fengtongxue