MINOR: [C++][Gandiva] cast to unsigned char before ctype calls#50124
Merged
Conversation
metsw24-max
force-pushed
the
gandiva-ctype-unsigned-char
branch
from
June 16, 2026 09:14
52038a2 to
b314883
Compare
Contributor
Author
Member
|
Could you use our PR template instead of removing it entirely? |
Contributor
Author
|
Done, sorry about that. Restored the template and filled in the sections. |
metsw24-max
force-pushed
the
gandiva-ctype-unsigned-char
branch
from
July 6, 2026 11:57
b314883 to
8175886
Compare
Contributor
Author
|
Rebased onto main to pick up the tzdata-legacy fix from #50211. The AVX2 failure on the previous run was TestCastTimestampWithTZ (#50173), which came from the conda image moving to Ubuntu 24.04 rather than from this diff, and the JNI/ODBC failures were red on main at the time as well. The casts themselves are unchanged. |
|
After merging your PR, Conbench analyzed the 3 benchmarking runs that have been run so far on merge-commit 1828740. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
The Gandiva precompiled string and time helpers feed raw
charbytes intoisdigit/isxdigit/isalpha/toupper. Wherecharis signed, any byte above 0x7f (so any multi-byte UTF-8 value coming from untrusted column data) is sign-extended to a negativeint, which sits outside theunsigned char/EOFdomain those functions are defined for. glibc tolerates it, but a strict ctype implementation indexes its lookup table before the start of the array, which is undefined behaviour.gdv_function_stubs.ccalready casts tounsigned charat its call sites; these helpers were missed.What changes are included in this PR?
Cast each ctype argument to
unsigned charat the call site:time.cc:castDATE_utf8,castTIMESTAMP_utf8,castTIME_utf8string_ops.cc:binary_string, thecast<INT>_varbinarymacro,from_hex_utf8,soundex_utf8The sweep covers both files so no call site is left behind. There is no behaviour change where
charis unsigned or the ctype implementation is lenient; it just keeps the argument in range everywhere.Are these changes tested?
No new test. This is a localised undefined-behaviour fix with no observable change on the platforms CI runs (
charis unsigned or the ctype lookup is lenient there), and the existing Gandiva precompiled tests already exercise these functions.Are there any user-facing changes?
No.