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

adds changes for correctly setting stream position when error occurs while reading binary int64 #244

Merged
merged 4 commits into from
May 24, 2021

Conversation

desaikd
Copy link
Contributor

@desaikd desaikd commented May 21, 2021

Description of changes:
This PR works on setting stream position correctly when error occurs in reading binary int64 value.

Changes:

  • Changed reader method for binary int64 value to set the position of stream back to the start of value in order to not consume it in error cases.

Test:

  • Added tests for checking the edge case(integer of size 8 bytes) that doesn't fit in int64 throwing overflow error and then reading it as big integer.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@desaikd desaikd requested a review from almann May 21, 2021 18:50
ionc/ion_reader_binary.c Outdated Show resolved Hide resolved
ionc/ion_reader_binary.c Outdated Show resolved Hide resolved
ionc/ion_reader_binary.c Outdated Show resolved Hide resolved
ionc/ion_reader_binary.c Outdated Show resolved Hide resolved
test/test_ion_binary.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@almann almann left a comment

Choose a reason for hiding this comment

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

:shipit:

ionc/ion_reader_binary.c Outdated Show resolved Hide resolved
Comment on lines 436 to 438
TEST(IonBinaryReader, ReaderNegativeThresholdForInt64) {
test_ion_binary_reader_threshold_for_int64((BYTE *)"\xE0\x01\x00\xEA\x38\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 13, "-18446744073709551615");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Very minor, but I think variants of the test with 2 ** 63 is interesting '\x80\x00\x00\x00\x00\x00\x00\x00' should fail for positive int, but not negative int (since -2 ** 63 fits as two's complement representation 0x8000000000000000).

almann
almann previously approved these changes May 24, 2021
Copy link
Contributor

@almann almann left a comment

Choose a reason for hiding this comment

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

See previous comment around testing, but otherwise this looks good.

Copy link
Contributor

@almann almann left a comment

Choose a reason for hiding this comment

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

🚢 it!

@desaikd desaikd merged commit 2671a08 into master May 24, 2021
desaikd added a commit to amazon-ion/ion-rust that referenced this pull request May 27, 2021
See amazon-ion/ion-c#244 for the fix around setting the binary reader's stream position back to the start of value when an error occurs in reading int64 value.

Fixes #218
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.

2 participants