AlexStocks commented on code in PR #3812:
URL: https://github.com/apache/dubbo-go/pull/3812#discussion_r4577993220


##########
protocol/triple/triple_protocol/codec.go:
##########
@@ -340,10 +343,26 @@ func (c *protoWrapperCodec) Unmarshal(binary []byte, 
message any) error {
                return nil
        }
 
+       // Legacy gRPC-wire non-IDL responses used a one-argument request 
wrapper.
+       // Field 3 uniquely identifies that historical layout. Select by 
schema, never
+       // by a failed payload decode, then apply the same response allowlist.
+       if c.runtimeCodecs != nil {
+               var legacy interoperability.TripleRequestWrapper
+               if err := proto.Unmarshal(binary, &legacy); err == nil && 
len(legacy.Args) > 0 {

Review Comment:
   💭 **这条注释与实际判断条件不符,且该分支会让下面的「Response format」分支在带数据的响应上不可达**
   
   注释写的是 `Field 3 uniquely identifies that historical layout. Select by schema, 
never by a failed payload decode`,但代码判断的是字段 2(`len(legacy.Args) > 0`),字段 
3(`argTypes`)从未被检查。
   
   **实测**(head `f2077f7d`,在 `probes/` 的一次性副本里跑):
   
   ```go
   resp := &interoperability.TripleResponseWrapper{SerializeType: "hessian2", 
Data: []byte{0x01, 0x02, 0x03}}
   raw, _ := proto.Marshal(resp)
   var req interoperability.TripleRequestWrapper
   proto.Unmarshal(raw, &req)
   // 输出:serializeType="hessian2" args=1 argTypes=0  →  len(Args)>0 = true
   ```
   
   `TripleResponseWrapper.data` 是字段 2(singular 
bytes),`TripleRequestWrapper.args` 也是字段 2(repeated bytes),wire type 
相同,所以**任何带数据的正常响应包装都能成功解码成请求包装并得到 `args=1`**。结论:当 `c.runtimeCodecs != 
nil`(即所有经过插件化配置的 client)时,这个 legacy 分支会先命中,下面 `// Response format: 
TripleResponseWrapper` 分支只在 `Data` 为空(null/void 响应)时才可达。
   
   **目前不是正确性问题**:两个分支最终都执行 `inner.Unmarshal(<payload>, message)`,allowlist 
也相同,所以解码结果一致;差别只在错误包装(legacy 分支直接返回 `err`,response 分支加 `wrapper codec:` 
前缀)。因此本条按维护性问题提出,不按缺陷定级。
   
   **建议**(二选一):
   1. 若确实要「按 schema 选」:检查字段 3(例如 `len(legacy.ArgTypes) > 
0`)或显式比对两种包装的字段组合,让注释与实现一致;
   2. 若两者本就等价:删除 legacy 分支,或把它移到 response 分支之后仅作兜底,并把注释改成「单参数 legacy 
请求包装与响应包装在字节层等价」。
   
   无论选哪种,建议补一条用例:把一个带 `Data` 的 `TripleResponseWrapper` 直接喂给 
`protoWrapperCodec.Unmarshal`,断言走的是哪条分支。现在的 6 个插件场景测试与 `serialization_test.go` 
都没有覆盖这个分支选择。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to