From 7f97aca5e6ced326177d6b4015af8228788c241b Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Fri, 27 Nov 2020 17:41:47 +0900 Subject: [PATCH] Fix skipValue --- decode_context.go | 12 +++++++++++- decode_stream.go | 9 ++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/decode_context.go b/decode_context.go index dd68530..13ec668 100644 --- a/decode_context.go +++ b/decode_context.go @@ -25,9 +25,16 @@ func skipValue(buf []byte, cursor int64) (int64, error) { braceCount := 0 bracketCount := 0 buflen := int64(len(buf)) + start := cursor for { switch buf[cursor] { - case '\000': + case nul: + if start == cursor { + return cursor, errUnexpectedEndOfJSON("value of object", cursor) + } + if braceCount == 0 && bracketCount == 0 { + return cursor, nil + } return cursor, errUnexpectedEndOfJSON("value of object", cursor) case '{': braceCount++ @@ -40,6 +47,9 @@ func skipValue(buf []byte, cursor int64) (int64, error) { } case ']': bracketCount-- + if braceCount == 0 && bracketCount == -1 { + return cursor, nil + } case ',': if bracketCount == 0 && braceCount == 0 { return cursor, nil diff --git a/decode_stream.go b/decode_stream.go index fdb239e..063dcd7 100644 --- a/decode_stream.go +++ b/decode_stream.go @@ -111,12 +111,19 @@ func (s *stream) skipValue() error { s.skipWhiteSpace() braceCount := 0 bracketCount := 0 + start := s.cursor for { switch s.char() { case nul: if s.read() { continue } + if start == s.cursor { + return errUnexpectedEndOfJSON("value of object", s.totalOffset()) + } + if braceCount == 0 && bracketCount == 0 { + return nil + } return errUnexpectedEndOfJSON("value of object", s.totalOffset()) case '{': braceCount++ @@ -129,7 +136,7 @@ func (s *stream) skipValue() error { } case ']': bracketCount-- - if braceCount == 0 && bracketCount == 0 { + if braceCount == 0 && bracketCount == -1 { return nil } case ',':