You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "ahaostudy (via GitHub)" <gi...@apache.org> on 2023/10/31 14:23:02 UTC

[PR] fix issue where Decoder panics when decoding an Object containing a Map with int8/int16 as key or value type [dubbo-go-hessian2]

ahaostudy opened a new pull request, #366:
URL: https://github.com/apache/dubbo-go-hessian2/pull/366

   <!--  Thanks for sending a pull request! 
   -->
   
   **What this PR does**:
   fix issue where Decoder panics when decoding an Object containing a Map with int8/int16 as key or value type.
   
   **Which issue(s) this PR fixes**:
   <!--
   *Automatically closes linked issue when PR is merged.
   Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
   _If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
   -->
   https://github.com/kitex-contrib/codec-dubbo/issues/55
   
   **Special notes for your reviewer**:
   Currently, dubbo-go-hessian2 is unable to correctly decode `object` that contain `map` with `int8` / `int16` as keys or values, resulting in a panic during decoding.
   
   I am a developer from the Kitex framework, and currently, [DubboCodec](https://github.com/kitex-contrib/codec-dubbo) is using dubbo-go-hessian2 as its encoder/decoder. I hope to fix this issue through this PR, allowing us to support decoding of `int8` and `int16` types.
   
   ![img_v2_f5ff3858-80ba-4b3f-8e15-3794d2109ccg](https://github.com/apache/dubbo-go-hessian2/assets/92586826/0aba6ff9-e131-4d93-b882-13c6e8d49728)
   
   **Does this PR introduce a user-facing change?**:
   <!--
   If no, just write "NONE" in the release-note block below.
   If yes, a release note is required:
   Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
   -->
   ```release-note
   NONE
   ```


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix Decoder failed to decode int8/int16 type values of map field in struct [dubbo-go-hessian2]

Posted by "tiltwind (via GitHub)" <gi...@apache.org>.
tiltwind commented on code in PR #366:
URL: https://github.com/apache/dubbo-go-hessian2/pull/366#discussion_r1378415059


##########
map_test.go:
##########
@@ -182,3 +182,42 @@ func TestJavaMap(t *testing.T) {
 	RegisterPOJO(customMap)
 	testJavaDecode(t, "customArgTypedFixed_CustomMap", customMap)
 }
+
+type Obj struct {
+	Map8  map[int8]int8
+	Map16 map[int16]int16
+	Map32 map[int32]int32
+}
+
+func (Obj) JavaClassName() string {
+	return ""
+}
+
+func TestMapInObject(t *testing.T) {
+	var (
+		obj Obj
+		e   *Encoder
+		d   *Decoder
+		err error
+		res interface{}
+	)
+
+	obj = Obj{
+		Map8:  map[int8]int8{1: 2, 3: 4},
+		Map16: map[int16]int16{1: 2, 3: 4},
+		Map32: map[int32]int32{1: 2, 3: 4},
+	}
+
+	e = NewEncoder()
+	e.Encode(obj)
+	if len(e.Buffer()) == 0 {
+		t.Fail()
+	}
+
+	d = NewDecoder(e.Buffer())
+	res, err = d.Decode()
+	if err != nil {
+		t.Errorf("Decode() = %+v", err)
+	}
+	t.Logf("decode(%v) = %v, %v\n", obj, res, err)

Review Comment:
   should check whether the decode value is equal to the original 



-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix Decoder failed to decode int8/int16 type values of map field in struct [dubbo-go-hessian2]

Posted by "jasondeng1997 (via GitHub)" <gi...@apache.org>.
jasondeng1997 merged PR #366:
URL: https://github.com/apache/dubbo-go-hessian2/pull/366


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix Decoder failed to decode int8/int16 type values of map field in struct [dubbo-go-hessian2]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #366:
URL: https://github.com/apache/dubbo-go-hessian2/pull/366#issuecomment-1788520332

   ## [Codecov](https://app.codecov.io/gh/apache/dubbo-go-hessian2/pull/366?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#366](https://app.codecov.io/gh/apache/dubbo-go-hessian2/pull/366?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (c4fcd98) into [master](https://app.codecov.io/gh/apache/dubbo-go-hessian2/commit/f0fbe40e207cc5ba0cb76b1dcc0c8db2aee877bf?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (f0fbe40) will **increase** coverage by `0.24%`.
   > The diff coverage is `100.00%`.
   
   > :exclamation: Current head c4fcd98 differs from pull request most recent head fbdccbe. Consider uploading reports for the commit fbdccbe to get more accurate results
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #366      +/-   ##
   ==========================================
   + Coverage   68.98%   69.23%   +0.24%     
   ==========================================
     Files          28       28              
     Lines        3140     3146       +6     
   ==========================================
   + Hits         2166     2178      +12     
   + Misses        751      745       -6     
     Partials      223      223              
   ```
   
   
   | [Files](https://app.codecov.io/gh/apache/dubbo-go-hessian2/pull/366?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [map.go](https://app.codecov.io/gh/apache/dubbo-go-hessian2/pull/366?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWFwLmdv) | `63.81% <100.00%> (+4.23%)` | :arrow_up: |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix Decoder failed to decode int8/int16 type values of map field in struct [dubbo-go-hessian2]

Posted by "ahaostudy (via GitHub)" <gi...@apache.org>.
ahaostudy commented on code in PR #366:
URL: https://github.com/apache/dubbo-go-hessian2/pull/366#discussion_r1378448320


##########
map_test.go:
##########
@@ -182,3 +182,42 @@ func TestJavaMap(t *testing.T) {
 	RegisterPOJO(customMap)
 	testJavaDecode(t, "customArgTypedFixed_CustomMap", customMap)
 }
+
+type Obj struct {
+	Map8  map[int8]int8
+	Map16 map[int16]int16
+	Map32 map[int32]int32
+}
+
+func (Obj) JavaClassName() string {
+	return ""
+}
+
+func TestMapInObject(t *testing.T) {
+	var (
+		obj Obj
+		e   *Encoder
+		d   *Decoder
+		err error
+		res interface{}
+	)
+
+	obj = Obj{
+		Map8:  map[int8]int8{1: 2, 3: 4},
+		Map16: map[int16]int16{1: 2, 3: 4},
+		Map32: map[int32]int32{1: 2, 3: 4},
+	}
+
+	e = NewEncoder()
+	e.Encode(obj)
+	if len(e.Buffer()) == 0 {
+		t.Fail()
+	}
+
+	d = NewDecoder(e.Buffer())
+	res, err = d.Decode()
+	if err != nil {
+		t.Errorf("Decode() = %+v", err)
+	}
+	t.Logf("decode(%v) = %v, %v\n", obj, res, err)

Review Comment:
   done



-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org