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

unexpected behavior when buffer ends with backslash #384

Closed
KimHyeonwoo opened this issue Jul 18, 2022 · 0 comments · Fixed by #383
Closed

unexpected behavior when buffer ends with backslash #384

KimHyeonwoo opened this issue Jul 18, 2022 · 0 comments · Fixed by #383
Labels
bug Something isn't working

Comments

@KimHyeonwoo
Copy link
Contributor

KimHyeonwoo commented Jul 18, 2022

Version

v0.9.10

Summary

In double quote case (") of Stream.skipObject function, if s.buf ends with backslash (\), the character right next to backslash doesn't escaped.

Way to reproduce this issue

test.json

{"data": "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\""}
  • 511th character of the json is backslash
  • initial buffer size of the stream is 512, so 512th character of a buffer is \0
  • 512th character of the json is double quote, which is doesn't escaped and caused this issue

main.go

package main

import (
	"fmt"
	"os"

	"github.com/goccy/go-json"
)

type test struct{}

func (t test) UnmarshalJSON(bytes []byte) error {
	return nil
}

func main() {
	file, err := os.Open("./test.json")
	if err != nil {
		panic(fmt.Errorf("file open failed: %w", err))
	}
	defer file.Close()
	d := json.NewDecoder(file)
	var t test
	if err := d.Decode(&t); err != nil {
		panic(fmt.Errorf("decode failed: %w", err))
	}
}

output

panic: decode failed: json: string of object unexpected end of JSON input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants