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

jsoniter: Fix errors during reading integers from chunked io.Reader #477

Merged

Conversation

mrVanboy
Copy link
Contributor

This commit fixes bug in Iterator.assertInteger method if the next
conditions are met:

  • Iterator reads data from io.Reader,
  • expected value is 0 (zero)
  • Iterator.tail == Iterator.head + 1
  • Iterator.tail < len(Iterator.buf)
  • value in the buffer after Iterator.tail is presented from the previous read and has '.' character.

Typical error which user cal see is:

  • assertInteger: can not decode float as int, error found in #X byte of ...

Regression test added for checking the correct behaviour.

Fixes #476

@codecov
Copy link

codecov bot commented Jul 18, 2020

Codecov Report

Merging #477 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #477   +/-   ##
=======================================
  Coverage   86.29%   86.29%           
=======================================
  Files          41       41           
  Lines        5115     5115           
=======================================
  Hits         4414     4414           
  Misses        560      560           
  Partials      141      141           
Impacted Files Coverage Δ
iter_int.go 90.37% <100.00%> (ø)
reflect_struct_decoder.go 82.49% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9461257...cd30fdf. Read the comment docs.

@AllenX2018
Copy link
Collaborator

Thanks for the bug report and the pr. I will check it in the next few days.

@mrVanboy
Copy link
Contributor Author

mrVanboy commented Aug 4, 2020

@AllenX2018 any updates plz 🙏 ? We already using our fork with the current PR branch for a couple of weeks in production and we haven't noticed any issues.

@AllenX2018
Copy link
Collaborator

Hi! Sorry for the late reply. I leave a review comment and please check it.

iter_int_test.go Outdated
@@ -0,0 +1,101 @@
package jsoniter_test
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you move this test case to the jsoniter_int_test.go under misc_tests directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Wasn't sure originally where to place this test 🤷

This commit fixes bug in Iterator.assertInteger method if the next
conditions are met:
- Iterator reads data from `io.Reader`,
- expected value is `0` (zero)
- `Iterator.tail == Iterator.head + 1`
- `Iterator.tail < len(Iterator.buf)`
- value in the buffer after `Iterator.tail` is presented from the previous read and has '.' character.

Typical error which user cal see is:
- assertInteger: can not decode float as int, error found in #X byte of ...

Regression test added for checking the correct behaviour.

Fixes json-iterator#476
@mrVanboy mrVanboy force-pushed the ib/476-fix-assertInteger-bug branch from ae689be to cd30fdf Compare Aug 5, 2020
@AllenX2018 AllenX2018 merged commit 6821bec into json-iterator:master Aug 6, 2020
2 checks passed
@AllenX2018
Copy link
Collaborator

Merged. Thanks!

zhenzou pushed a commit to zhenzou/jsoniter that referenced this pull request Feb 2, 2022
…son-iterator#477)

This commit fixes bug in Iterator.assertInteger method if the next
conditions are met:
- Iterator reads data from `io.Reader`,
- expected value is `0` (zero)
- `Iterator.tail == Iterator.head + 1`
- `Iterator.tail < len(Iterator.buf)`
- value in the buffer after `Iterator.tail` is presented from the previous read and has '.' character.

Typical error which user cal see is:
- assertInteger: can not decode float as int, error found in #X byte of ...

Regression test added for checking the correct behaviour.

Fixes json-iterator#476
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

Successfully merging this pull request may close these issues.

assertInteger: can not decode float as int for valid input from chunked reader
2 participants