Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
winnyrain opened this issue Sep 12, 2023 · 0 comments
Open

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

winnyrain opened this issue Sep 12, 2023 · 0 comments

Comments

@winnyrain
Copy link
Contributor

winnyrain commented Sep 12, 2023

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())
        {
@winnyrain winnyrain changed the title varchar字段为null时报内存错误 Websocket模式varchar字段为null时报内存错误 Sep 13, 2023
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

No branches or pull requests

1 participant