Skip to content

Commit fefc46e

Browse files
authored
fix:(conv/j2t) not recurse in tb_write_default_or_empty to avoid dead-looping on cycle-referred struct (#89)
* fix: judge escape string wrong * fix: not recurse in `tb_write_default_or_empty` to avoid dead-loop * change test * update README
1 parent 405ebed commit fefc46e

File tree

13 files changed

+49941
-50172
lines changed

13 files changed

+49941
-50172
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ CFLAGS_avx := -msse -mno-sse4 -mavx -mpclmul -mno-avx2 -mstack-alignment=0 -DUS
3131
CFLAGS_avx2 := -msse -mno-sse4 -mavx -mpclmul -mavx2 -mstack-alignment=0 -DUSE_AVX=1 -DUSE_AVX2=1
3232
CFLAGS_sse := -msse -mno-sse4 -mno-avx -mno-avx2 -mpclmul
3333

34-
CC_amd64 := /opt/homebrew/Cellar/llvm\@14/14.0.6/bin/clang
34+
CC_amd64 := clang
3535
ASM2ASM_amd64 := tools/asm2asm/asm2asm.py
3636

3737
CFLAGS := -mno-red-zone

README.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ Dynamic-Go for Protobuf protocol: [introduction.md](./proto/INTRODUCTION.md)
1212

1313
### thrift
1414
Thrift IDL parser and message operators. It can parse thrift IDL in runtime and handle thrift data in generic way.
15-
[DOC](thrift/README.md)
1615

1716
#### thrift/generic
1817
Reflection APIs to search, modify, deserialize, serialize thrift value **with or without** runtime type descriptor.
19-
[DOC](thrift/generic/README.md)
2018

2119
#### thrift/base
2220
The meta data about message transportation, including caller, address, log-id, etc. It is mainly used for `conv` (protocol convertion) modules.
@@ -26,40 +24,32 @@ Built-in implementation of thrid-party annotations, see [thrift_idl_annotation_s
2624

2725
### proto
2826
Protobuf IDL parser and message operators. It can parse protobuf IDL in runtime and handle protobuf data in generic way.
29-
[DOC](proto/README.md)
3027

3128
#### proto/generic
3229
Reflection APIs to search, modify, deserialize, serialize protobuf value **with or without** runtime descriptor.
33-
[DOC](proto/generic/README.md)
3430

3531
#### proto/protowire
3632
Protobuf data encode and decode APIs. It parses and formats the low-level raw wire encoding. It is modified from Protobuf official code [`encoding/protowire`](https://pkg.go.dev/google.golang.org/protobuf/encoding/protowire).
37-
[DOC](proto/protowire/README.md)
3833

3934
#### proto/binary
4035
BinaryProtocol tool for Protobuf Protocol. It can read, wirte and skip fields directly on binary data of protobuf message.
41-
[DOC](proto/binary/README.md)
4236

4337
### http
4438
Http request/response wrapper interfaces. They are mainly used to pass http values on `http<>thrift` conversion.
45-
[DOC](http/README.md)
4639

4740
### conv
4841
Protocol convertors. Based on reflecting ability of `thrift`, `json` and `protobuf` modules, it can convert message from one protocol into another.
4942

5043
#### conv/j2t
5144
Convert JSON value or JSON-body HTTP request into thrift message.
52-
[DOC](conv/j2t/README.md)
5345

5446
#### conv/t2j
5547
Convert thrift message to JSON value or JSON-body HTTP response.
56-
[DOC](conv/t2j/README.md)
5748

5849
#### conv/j2p
5950
Convert JSON value into protobuf message.
60-
[DOC](conv/j2p/README.md)
6151

6252
#### conv/p2j
6353
Convert protobuf message into JSON value.
64-
[DOC](conv/p2j/README.md)
54+
6555

conv/j2t/conv_amd64_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ import (
4141
"github.com/stretchr/testify/require"
4242
)
4343

44-
func init() {
45-
recursivelyWrite = true
46-
}
47-
4844
func TestError(t *testing.T) {
4945
desc := getExampleDesc()
5046

conv/j2t/conv_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,11 @@ func getNullErrData() []byte {
349349
return out
350350
}
351351

352-
var recursivelyWrite = false
353-
354352
func TestWriteDefault(t *testing.T) {
355353
desc := getExampleDesc()
356354
data := []byte(`{"Path":"<>"}`)
357355
exp := example3.NewExampleReq()
358356
exp.InnerBase = &example3.InnerBase{}
359-
println(recursivelyWrite)
360-
if recursivelyWrite {
361-
exp.InnerBase = sample.GetEmptyInnerBase3()
362-
}
363357
data2 := []byte(`{"Path":"<>","Base":{}}`)
364358
err := json.Unmarshal(data2, exp)
365359
require.Nil(t, err)
@@ -400,9 +394,6 @@ func TestWriteRequired(t *testing.T) {
400394
t.Run("http-mapping", func(t *testing.T) {
401395
exp := example3.NewExampleReq()
402396
exp.InnerBase = &example3.InnerBase{}
403-
if recursivelyWrite {
404-
exp.InnerBase = sample.GetEmptyInnerBase3()
405-
}
406397
data2 := []byte(`{"Path":"","Base":{}}`)
407398
err := json.Unmarshal(data2, exp)
408399
require.Nil(t, err)

conv/j2t/impl_fallback.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (self *BinaryConv) doRecurse(ctx context.Context, s string, jp int, desc *t
190190
ret = jp
191191

192192
var key string
193-
if v.Ep >= int64(ret) {
193+
if v.Ep >= 0 && v.Ep < int64(ret) {
194194
key, err = strconv.Unquote(s[v.Iv-1 : ret])
195195
if err != nil {
196196
return
@@ -271,7 +271,7 @@ func (self *BinaryConv) doRecurse(ctx context.Context, s string, jp int, desc *t
271271
ret = jp
272272

273273
var key string
274-
if v.Ep >= int64(ret) {
274+
if v.Ep >= 0 && v.Ep < int64(ret) {
275275
key, err = strconv.Unquote(s[v.Iv-1 : ret])
276276
if err != nil {
277277
return

0 commit comments

Comments
 (0)