Skip to content

Commit fe9fc77

Browse files
HuaHuaYwgtmac
authored andcommitted
ORC-2027: [C++] Fix undefined behavior in DoubleColumnReader::readFloat()
### What changes were proposed in this pull request? Unaligned reads are UB in C++. We can not guarantee that the `bufferPointer_` pointer is aligned by `alignof(int32_t)`. ### How was this patch tested? Use UBsan to test in private repo. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #2444 from HuaHuaY/fix_issue_2027. Lead-authored-by: Zehua Zou <zehuazou2000@gmail.com> Co-authored-by: Zehua Zou <41586196+HuaHuaY@users.noreply.github.com> Signed-off-by: Gang Wu <ustcwg@gmail.com> (cherry picked from commit c4fa9fa) Signed-off-by: Gang Wu <ustcwg@gmail.com>
1 parent bda8584 commit fe9fc77

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

c++/src/ColumnReader.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ namespace orc {
421421
int32_t bits = 0;
422422
if (bufferEnd_ - bufferPointer_ >= 4) {
423423
if (isLittleEndian) {
424-
bits = *(reinterpret_cast<const int32_t*>(bufferPointer_));
424+
memcpy(&bits, bufferPointer_, sizeof(bits));
425425
} else {
426426
bits = static_cast<unsigned char>(bufferPointer_[0]);
427427
bits |= static_cast<unsigned char>(bufferPointer_[1]) << 8;

0 commit comments

Comments
 (0)