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

Further investigate recursion depth and associated mem-consumption #211

Open
liamsi opened this issue Jul 30, 2018 · 1 comment
Open

Further investigate recursion depth and associated mem-consumption #211

liamsi opened this issue Jul 30, 2018 · 1 comment
Labels

Comments

@liamsi
Copy link
Contributor

liamsi commented Jul 30, 2018

Not too long ago the code snippet below produced a 100KB JSON message which consumed about 1,3 Gb memory while decoding.

package main
import (
"strings"
"github.com/tendermint/go-amino"
)
type Tree struct {
    Value int  `json:"v"`
    Children []Tree `json:"c"`
}
func main() {
    approxTargetLen := 100000
    msgBegin := `{"v":1,"c":[`
    msgEnd := `]}`
    repeatCnt := int(approxTargetLen / (len(msgBegin) + len(msgEnd)))
    recurMsg := strings.Repeat(msgBegin,repeatCnt )
    recurMsg = strings.Join([]string{recurMsg,strings.Repeat("]}",repeatCnt)},"")
    cst := Tree{}
    cdc := amino.NewCodec()
    cdc.UnmarshalJSON([]byte(recurMsg), &cst)
}

Although this is not the case anymore (it only consumes 45 Mb), we should make sure that we either use less recursion or limit the recursion depth (or fully understand why this isn't necessary anymore).

@liamsi liamsi added the security label Aug 2, 2018
@ValarDragon
Copy link
Contributor

ref #197

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants