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

Resolve 424: Set (*Stream).bufSize equal to size of (*Stream).buf when it resized #428

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vadiminshakov
Copy link

Resolve issue 464

@vadiminshakov
Copy link
Author

@goccy

@codecov-commenter
Copy link

Codecov Report

Merging #428 (c360573) into master (a2149a5) will increase coverage by 0.03%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #428      +/-   ##
==========================================
+ Coverage   76.95%   76.99%   +0.03%     
==========================================
  Files          55       55              
  Lines       18806    18807       +1     
==========================================
+ Hits        14472    14480       +8     
+ Misses       3695     3690       -5     
+ Partials      639      637       -2     

@@ -270,6 +270,7 @@ func stringBytes(s *Stream) ([]byte, error) {
r, size := utf8.DecodeRune(s.buf[cursor:])
if r == utf8.RuneError {
s.buf = append(append(append([]byte{}, s.buf[:cursor]...), runeErrBytes...), s.buf[cursor+1:]...)
s.bufSize = int64(len(s.buf))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vadiminshakov I would like some more explanation as to why the bufSize needs to be changed at this place

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We get panic here https://github.com/goccy/go-json/blob/master/internal/decoder/stream.go#L201

Panic occurs because the cursor is pointing out of bounds s.buf.
s.buf slice boundaries are set here: https://github.com/goccy/go-json/blob/master/internal/decoder/stream.go#L195)

But these boundaries do not match where the cursor is pointing. My change makes it so that the cursor does not go beyond the buffer bounds (on s.buf resize we change bufSize accordingly).

@goccy goccy added the bug fix label Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic from stream overflow
3 participants