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

Parsing json with invalid bytes inside strings on arm64 causes memory corruption #739

Closed
brennan-airtime opened this issue Feb 12, 2025 · 2 comments
Assignees

Comments

@brennan-airtime
Copy link

brennan-airtime commented Feb 12, 2025

Tried on:
go: 1.22.x, 1.23.5, 1.23.6
github.com/bytedance/sonic v1.12.2
github.com/bytedance/sonic v1.12.8 (latest at time of writing)

We noticed that we were getting panics running on graviton in aws. Running locally through qemu I see issues with null and newlines inside of json strings when using ConfigDefault.

package main

import (
	"fmt"

	"github.com/bytedance/sonic"
)

type foo struct{}

func main() {
	var bar foo
	s := `{"a":"b
c"}`
	fmt.Println(sonic.ConfigStd.UnmarshalFromString(s, &bar))
	fmt.Println(sonic.Config{ValidateString: true}.Froze().UnmarshalFromString(s, &bar))
	fmt.Println(sonic.ConfigDefault.UnmarshalFromString(s, &bar))
}

Running it a few times every so often I get the signal handler problem. Even when it works obviously the index is way out of bounds so clearly a memory issue.

$ GOARCH=arm64 go run main.go
"Syntax error at index 6: control chars in string\n\n\t{\"a\":\"b\nc\"}\n\t......^....\n"
"Syntax error at index 6: control chars in string\n\n\t{\"a\":\"b\nc\"}\n\t......^....\n"
"Syntax error at index 2113627: expect a `,` or `}`\n\n\t{\"a\":\"b\nc\"}\n\t^\n"
$ GOARCH=arm64 go run ./cmd/foo/main.go
"Syntax error at index 6: control chars in string\n\n\t{\"a\":\"b\nc\"}\n\t......^....\n"
"Syntax error at index 6: control chars in string\n\n\t{\"a\":\"b\nc\"}\n\t......^....\n"
fatal: bad g in signal handler
exit status 2
@brennan-airtime brennan-airtime changed the title Parsing json strings with invalid bytes inside on arm64 causes memory corruption Parsing json with invalid bytes inside strings on arm64 causes memory corruption Feb 12, 2025
@liuq19
Copy link
Collaborator

liuq19 commented Feb 13, 2025

thanks, we will fix it

@liuq19
Copy link
Collaborator

liuq19 commented Feb 19, 2025

Fixed by #745

@liuq19 liuq19 closed this as completed Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants