161 Star 1.4K Fork 396

RHQYZ/DotNetCore.SKIT.FlurlHttpClient.Wechat

 / 详情

会话内容存档拉取聊天记录存在JSON转义的BUG

已完成
创建于  
2024-01-02 15:48

问题类型

请在此选择你的问题类型:

  • 报告缺陷:发现源代码中的漏洞、运行发生的异常、或文档里的错误。

关于问题或建议的简单描述

请在此填写你遇到的问题或你想要的功能。
在使用WechatWorkFinanceClient拉取聊天记录时出现了Json转义失败的错误提示

与问题或建议相关的源代码

对于报告缺陷,请在此粘贴与问题相关的代码,或提供可复现问题的最小化项目(可提供仓库地址或 GitHub Gist)。

对于请求新功能,请在此粘贴已有实现思路或解决方案。

注意,请不要以截图形式提供代码。

 try
                {
                    int ret = /* 获取聊天记录数据 */
                        IsRunOnWindows() ? FinanceDllWindowsPInvoker.GetChatData(_sdkPtr, request.LastSequence, request.Limit, _proxyAddress!, _proxyAuthentication!, (request.Timeout ?? _timeout) / 1000, dataPtr) :
                        IsRunOnLinux() ? FinanceDllLinuxPInvoker.GetChatData(_sdkPtr, request.LastSequence, request.Limit, _proxyAddress!, _proxyAuthentication!, (request.Timeout ?? _timeout) / 1000, dataPtr) :
                        throw new PlatformNotSupportedException();
                    if (ret == 0)
                    {
                        //int dataSize = /* 获取聊天记录数据内容长度 */
                        //    IsRunOnWindows() ? FinanceDllWindowsPInvoker.GetSliceLen(dataPtr) :
                        //    IsRunOnLinux() ? FinanceDllLinuxPInvoker.GetSliceLen(dataPtr) :
                        //    throw new PlatformNotSupportedException();
                        IntPtr dataContentPtr = /* 获取聊天记录数据内容 */
                            IsRunOnWindows() ? FinanceDllWindowsPInvoker.GetContentFromSlice(dataPtr) :
                            IsRunOnLinux() ? FinanceDllLinuxPInvoker.GetContentFromSlice(dataPtr) :
                            throw new PlatformNotSupportedException();
                        string dataContent = MarshalerHelper.PtrToStringUTF8(dataContentPtr);

                        response = JsonSerializer.Deserialize<Models.GetChatRecordsResponse>(dataContent);
                        response.RawBytes = Encoding.UTF8.GetBytes(dataContent);
                    }

                    response.ReturnCode = ret;
                    return response;
                }
                catch (Exception ex)
                {
                    throw new WechatWorkFinanceException("Failed to fetch chat data. Please see the inner exception for more details.", ex);
                }

异常堆栈或异常原因
SKIT.FlurlHttpClient.Wechat.Work.WechatWorkFinanceException:
Failed to decrypt chat data. Please see the inner exception for more details.
---> System.Text.Json.JsonException: '0x14' is invalid within a JSON string. The string should be correctly escaped. Path: $.text.content | LineNumber: 0 | BytePositionInLine: 1143.
---> System.Text.Json.JsonReaderException: '0x14' is invalid within a JSON string. The string should be correctly escaped. LineNumber: 0 | BytePositionInLine: 1143.
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan1 bytes) at System.Text.Json.Utf8JsonReader.ConsumeStringAndValidate(ReadOnlySpan1 data, Int32 idx)
at System.Text.Json.Utf8JsonReader.ConsumeString()
at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker)
at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
at System.Text.Json.Utf8JsonReader.Read()
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
--- End of inner exception stack trace ---
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable1 actualByteCount) at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan1 json, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
at SKIT.FlurlHttpClient.Wechat.Work.SDK.Finance.WechatWorkFinanceClient.<>c__DisplayClass18_0.b__0()
--- End of inner exception stack trace ---
at SKIT.FlurlHttpClient.Wechat.Work.SDK.Finance.WechatWorkFinanceClient.<>c__DisplayClass18_0.b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at WechatWorkSystem.WechatWorkSdks.FinanceChatRecordProxy.DecryptChatRecordAsync(DecryptChatRecordRequest request, CancellationToken cancellationToken)


发生问题的运行环境

请在此填写以下几项内容:

  1. 操作系统:Windows Server 2012 R2
  2. .NET 版本:.NET 5.0
  3. 使用的模块及版本:SKIT.FlurlHttpClient.Wechat.Work.SDK.Finance
  4. 其他环境信息。

补充说明

请在此填写任何其他可以定位问题或帮助说明的信息。

评论 (5)

jstzxxy 创建了任务 1年前
jstzxxy 修改了描述 1年前
展开全部操作日志
628099 fudiwei 1627875359 RHQYZ 拥有者 1年前

方便断点看一下 dataContent 此时的值是什么吗?

注:如有敏感信息请脱敏后再上传。

jstzxxy-xxyganjun jstzxxy
回复 RHQYZ 拥有者
1年前

感谢大佬回复。为了让生产环境尽快恢复,我们已经跳过了特定的Sequence,研发也没有记录。 看后续是否可以捕获到类似异常。 我们一个月出现了两次相同的问题,这个频率还是有点高的

jstzxxy-xxyganjun jstzxxy
回复 RHQYZ 拥有者
1年前

{
"msgid": "3178079165664247997_1704039311141_external",
"action": "send",
"from": "wmK6y0EQAAoNqzHUd6oFE3zMu1YUXsMg",
"tolist": [
"wmK6y0EQAAcb5cF7NBNhXA8hE4P4wS8g",
"wmK6y0EQAA3XL3klG67NqMFGCvAHokcw",
"wmK6y0EQAA9s5D5O0PKCS3u_KxVryM0Q",
"wmK6y0EQAAyf0ixJb8e2E1e-ssMj0NOQ",
"wmK6y0EQAAH9e4UW58lT35oDFZBFzkAg",
"wmK6y0EQAAseRDDAmvhsMGCTx3oPzJUQ",
"wmK6y0EQAAKe9XS5vFX-MGv3ej8hdX-Q",
"wmK6y0EQAAdzh8g0W0KuQ3FOL5yBX67A",
"wmK6y0EQAAKfX7lnwy6N0pM31flk47BA",
"wmK6y0EQAAwYimBSA7tMsUxtLk5nVrGg",
"wmK6y0EQAA73J8IshRPpBxZ0V4kU1BJg",
"wmK6y0EQAA94G3L2Sud-2WcJX9yQ8w_A",
"wmK6y0EQAAJoU77ZRx89bCRUoevVZyrw",
"wmK6y0EQAA1gJiIl8W7V_xkhBlsvC94A",
"wmK6y0EQAAgNY1vKGusLyiDF32LFnEEA",
"wmK6y0EQAAkYibPtx2O8I1L10lWQjEQQ",
"wmK6y0EQAAxYvwm628u6vb6TYsfDfx1g",
"wmK6y0EQAA8SAoldyLI4LZBcemu0K3bg",
"wmK6y0EQAAJ6LvS8D-7qHDFRlAvPi5lQ",
"wmK6y0EQAAfpfWferFaBDm9NnORQrh9g",
"wmK6y0EQAAC_U-nBkGettmasVnML5L-g",
"wmK6y0EQAAzv9He_b5ueu47yhgbh9kCw"
],
"roomid": "wrK6y0EQAAAbheL4qb3MqFAOU-Og8beA",
"msgtime": 1704039307488,
"msgtype": "text",
"text": {
"content": "新年快乐,2024全部上岸\u0014[烟花]"
}
}

\u0014导致转义失败

628099 fudiwei 1627875359 RHQYZ 拥有者
回复 jstzxxy
1年前

可尝试指定 JSON 序列化器为 Newtonsoft.Json。

《如何指定 JSON 序列化器?》

默认的 System.Text.Json 对 JSON 格式的合法性要求比较严格。

RHQYZ 添加了
 
bug
标签
1年前
628099 fudiwei 1627875359 RHQYZ 拥有者 1年前

发布了 v2.25.0,尝试修复此问题,麻烦升级到此版本后再观察一下。

RHQYZ 任务状态待办的 修改为进行中 1年前
RHQYZ 任务状态进行中 修改为已完成 1年前

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
628099 fudiwei 1627875359 jstzxxy-xxyganjun
C#
1
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
git@gitee.com:fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
fudiwei
DotNetCore.SKIT.FlurlHttpClient.Wechat
DotNetCore.SKIT.FlurlHttpClient.Wechat

搜索帮助