|
29 | 29 | #include "arrow/util/logging.h" |
30 | 30 | #include "arrow/util/rle-encoding.h" |
31 | 31 | #include "arrow/util/string_view.h" |
| 32 | +#include "arrow/util/ubsan.h" |
32 | 33 |
|
33 | 34 | #include "parquet/exception.h" |
34 | 35 | #include "parquet/platform.h" |
@@ -609,7 +610,7 @@ inline int DecodePlain<ByteArray>(const uint8_t* data, int64_t data_size, int nu |
609 | 610 | int bytes_decoded = 0; |
610 | 611 | int increment; |
611 | 612 | for (int i = 0; i < num_values; ++i) { |
612 | | - uint32_t len = out[i].len = *reinterpret_cast<const uint32_t*>(data); |
| 613 | + uint32_t len = out[i].len = arrow::util::SafeLoadAs<uint32_t>(data); |
613 | 614 | increment = static_cast<int>(sizeof(uint32_t) + len); |
614 | 615 | if (data_size < increment) ParquetException::EofException(); |
615 | 616 | out[i].ptr = data + sizeof(uint32_t); |
@@ -719,7 +720,7 @@ class PlainByteArrayDecoder : public PlainDecoder<ByteArrayType>, |
719 | 720 | int bytes_decoded = 0; |
720 | 721 | while (i < num_values) { |
721 | 722 | if (bit_reader.IsSet()) { |
722 | | - uint32_t len = *reinterpret_cast<const uint32_t*>(data); |
| 723 | + uint32_t len = arrow::util::SafeLoadAs<uint32_t>(data); |
723 | 724 | increment = static_cast<int>(sizeof(uint32_t) + len); |
724 | 725 | if (data_size < increment) { |
725 | 726 | ParquetException::EofException(); |
@@ -752,7 +753,7 @@ class PlainByteArrayDecoder : public PlainDecoder<ByteArrayType>, |
752 | 753 | int bytes_decoded = 0; |
753 | 754 |
|
754 | 755 | while (i < num_values) { |
755 | | - uint32_t len = *reinterpret_cast<const uint32_t*>(data); |
| 756 | + uint32_t len = arrow::util::SafeLoadAs<uint32_t>(data); |
756 | 757 | int increment = static_cast<int>(sizeof(uint32_t) + len); |
757 | 758 | if (data_size < increment) ParquetException::EofException(); |
758 | 759 | builder->Append(data + sizeof(uint32_t), len); |
@@ -1103,7 +1104,7 @@ class DeltaLengthByteArrayDecoder : public DecoderImpl, |
1103 | 1104 | virtual void SetData(int num_values, const uint8_t* data, int len) { |
1104 | 1105 | num_values_ = num_values; |
1105 | 1106 | if (len == 0) return; |
1106 | | - int total_lengths_len = *reinterpret_cast<const int*>(data); |
| 1107 | + int total_lengths_len = arrow::util::SafeLoadAs<int32_t>(data); |
1107 | 1108 | data += 4; |
1108 | 1109 | this->len_decoder_.SetData(num_values, data, total_lengths_len); |
1109 | 1110 | data_ = data + total_lengths_len; |
@@ -1145,7 +1146,7 @@ class DeltaByteArrayDecoder : public DecoderImpl, |
1145 | 1146 | virtual void SetData(int num_values, const uint8_t* data, int len) { |
1146 | 1147 | num_values_ = num_values; |
1147 | 1148 | if (len == 0) return; |
1148 | | - int prefix_len_length = *reinterpret_cast<const int*>(data); |
| 1149 | + int prefix_len_length = arrow::util::SafeLoadAs<int32_t>(data); |
1149 | 1150 | data += 4; |
1150 | 1151 | len -= 4; |
1151 | 1152 | prefix_len_decoder_.SetData(num_values, data, prefix_len_length); |
|
0 commit comments