Skip to content

Commit 97122c9

Browse files
committed
FIX: Fix misaligned reads in C++ DBN decoding
1 parent 8ee923c commit 97122c9

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.15.0 - TBD
4+
5+
### Bug fixes
6+
- Fixed misaligned read undefined behavior when decoding records
7+
38
## 0.14.0 - 2023-11-23
49

510
This release adds support for DBN v2.

include/databento/dbn_decoder.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "databento/detail/shared_channel.hpp"
1111
#include "databento/enums.hpp" // Upgrade Policy
1212
#include "databento/ireadable.hpp"
13-
#include "databento/record.hpp"
13+
#include "databento/record.hpp" // Record, RecordHeader
1414

1515
namespace databento {
1616
// DBN decoder. Set upgrade_policy to control how DBN version 1 data should be
@@ -68,7 +68,9 @@ class DbnDecoder {
6868
std::unique_ptr<IReadable> input_;
6969
std::vector<std::uint8_t> read_buffer_;
7070
std::size_t buffer_idx_{};
71-
std::array<std::uint8_t, kMaxRecordLen> compat_buffer_{};
71+
// Must be 8-byte aligned for records
72+
alignas(
73+
RecordHeader) std::array<std::uint8_t, kMaxRecordLen> compat_buffer_{};
7274
Record current_record_{nullptr};
7375
};
7476
} // namespace databento

include/databento/live_blocking.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "databento/dbn.hpp" // Metadata
1212
#include "databento/detail/tcp_client.hpp" // TcpClient
1313
#include "databento/enums.hpp" // Schema, SType, VersionUpgradePolicy
14-
#include "databento/record.hpp" // Record
14+
#include "databento/record.hpp" // Record, RecordHeader
1515

1616
namespace databento {
1717
class ILogReceiver;
@@ -93,10 +93,13 @@ class LiveBlocking {
9393
std::uint8_t version_{};
9494
VersionUpgradePolicy upgrade_policy_;
9595
detail::TcpClient client_;
96-
std::array<char, kMaxStrLen> read_buffer_{};
96+
// Must be 8-byte aligned for records
97+
alignas(RecordHeader) std::array<char, kMaxStrLen> read_buffer_{};
9798
std::size_t buffer_size_{};
9899
std::size_t buffer_idx_{};
99-
std::array<std::uint8_t, kMaxRecordLen> compat_buffer_{};
100+
// Must be 8-byte aligned for records
101+
alignas(
102+
RecordHeader) std::array<std::uint8_t, kMaxRecordLen> compat_buffer_{};
100103
std::uint64_t session_id_;
101104
Record current_record_{nullptr};
102105
};

0 commit comments

Comments
 (0)