Skip to content

Websocket模式varchar字段为null时报内存错误 #269

@winnyrain

Description

@winnyrain

varchar字段为null时报如下错误:
System.AccessViolationException:“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”
应该是这段代码没有判断为空或者长度为0导致复制溢出(Websocket模式下,其他模式正常)
IoTSharp.Data.Taos\Protocols\TDWebSocket\TaosWebSocketContext.cs
GetValuePtr的这段的代码中IntPtr rowptr = IntPtr.Add(rowdata, offset);这句报错
private WSDataRow GetValuePtr(int ordinal)
{
var col = lstpColInfoData[ordinal];
int offset = 0;
short len = 0;
IntPtr data = IntPtr.Zero;
IntPtr rowdata = col.pData;
if (col.info.IS_VAR_DATA_TYPE() )
{
offset = col.varmeta.offset[_index];
IntPtr rowptr = IntPtr.Add(rowdata, offset);
len = Marshal.ReadInt16(rowptr, 0);
data = IntPtr.Add(rowptr, sizeof(Int16));
}

经分析,当varchar字段为空时offset=-1,rowdata=0x00000000,再复制就会导致指针错误,在if (col.info.IS_VAR_DATA_TYPE())前应该加个判断,如下

        if (rowdata == IntPtr.Zero)
            return new WSDataRow(TDengineDataType.TSDB_DATA_TYPE_NULL, rowdata, 0 , 0);

        if (col.info.IS_VAR_DATA_TYPE())
        {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions