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 c4fa9fa3d5b16630f5066d79bf4c36d171a2561d)
Signed-off-by: Gang Wu <ustcwg@gmail.com>
diff --git a/c++/src/ColumnReader.cc b/c++/src/ColumnReader.cc
index af434c3..8c9ddb4 100644
--- a/c++/src/ColumnReader.cc
+++ b/c++/src/ColumnReader.cc
@@ -421,7 +421,7 @@
int32_t bits = 0;
if (bufferEnd_ - bufferPointer_ >= 4) {
if (isLittleEndian) {
- bits = *(reinterpret_cast<const int32_t*>(bufferPointer_));
+ memcpy(&bits, bufferPointer_, sizeof(bits));
} else {
bits = static_cast<unsigned char>(bufferPointer_[0]);
bits |= static_cast<unsigned char>(bufferPointer_[1]) << 8;