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

Fix 64bit shift bug in avro reader #13276

Merged
merged 3 commits into from
May 13, 2023

Conversation

karthikeyann
Copy link
Contributor

Description

Replace 8 bit uint with 64bit so that the shift upto 64 happens correctly. (cudf::io::avro::container::get_encoded())

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@karthikeyann karthikeyann added bug Something isn't working 3 - Ready for Review Ready for review by team libcudf Affects libcudf (C++/CUDA) code. cuIO cuIO issue non-breaking Non-breaking change labels May 2, 2023
@karthikeyann karthikeyann requested a review from a team as a code owner May 2, 2023 18:37
@@ -27,8 +27,8 @@ template <>
uint64_t container::get_encoded()
{
uint64_t val = 0;
for (uint64_t len = 0; len < 64; len += 7) {
auto const byte = get_raw<uint8_t>();
for (uint8_t len = 0; len < 64; len += 7) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to auto.

@@ -27,8 +27,8 @@ template <>
uint64_t container::get_encoded()
Copy link
Contributor

Choose a reason for hiding this comment

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

another varint decode :)

for (uint64_t len = 0; len < 64; len += 7) {
auto const byte = get_raw<uint8_t>();
for (uint8_t len = 0; len < 64; len += 7) {
uint64_t const byte = get_raw<uint8_t>();
Copy link
Contributor

Choose a reason for hiding this comment

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

From some Godbolt experiments, it turns out that byte gets cast to a 32-bit type during (byte & 0x7f). So this is not a fix from 8-bit to 64-bit, but from 32 to 64.
This also explains why Avro reader was not completely broken :)
I would appreciate a comment about this above this line, and an update to the PR description. The original behavior is definitely not obvious.
Also, it would be great to add a test, but I'm not sure how feasible that is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0x7f is int32 literal. So, byte is upcasted to int32. That's why it worked for 32 bit.
Can't add test. I don't know avro well enough to add the test for this fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

To test, we would have to have an encoded int larger than uint32::max in the Avro file (and the int might have to be in the metadata??).
I'm okay with skipping the test here, as the fix is very safe.

@karthikeyann karthikeyann requested a review from vuule May 12, 2023 15:29
@vuule
Copy link
Contributor

vuule commented May 13, 2023

/merge

@rapids-bot rapids-bot bot merged commit 03f08f5 into rapidsai:branch-23.06 May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team bug Something isn't working cuIO cuIO issue libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants