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
Member

@Liamsi 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

This comment has been minimized.

Copy link
Member

@ValarDragon ValarDragon commented Aug 10, 2018

ref #197

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.