This is an automated email from the ASF dual-hosted git repository.

RyanSkraba pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/main by this push:
     new 343a9c749a Fix misaligned pointer use in BufferDetail.hh and 
BufferReader.hh (#3740)
343a9c749a is described below

commit 343a9c749a9320e7bf004ec6458cb27dfc5b61ab
Author: Andrew Pilloud <[email protected]>
AuthorDate: Tue May 5 11:16:56 2026 -0700

    Fix misaligned pointer use in BufferDetail.hh and BufferReader.hh (#3740)
---
 lang/c++/include/avro/buffer/BufferReader.hh        | 3 ++-
 lang/c++/include/avro/buffer/detail/BufferDetail.hh | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/lang/c++/include/avro/buffer/BufferReader.hh 
b/lang/c++/include/avro/buffer/BufferReader.hh
index 39b23fa708..a08dc25120 100644
--- a/lang/c++/include/avro/buffer/BufferReader.hh
+++ b/lang/c++/include/avro/buffer/BufferReader.hh
@@ -20,6 +20,7 @@
 #define avro_BufferReader_hh__
 
 #include "Buffer.hh"
+#include <cstring>
 #include <type_traits>
 
 #ifdef min
@@ -233,7 +234,7 @@ private:
         }
 
         if (sizeof(T) <= chunkRemaining()) {
-            val = *(reinterpret_cast<const T *>(addr()));
+            memcpy(&val, addr(), sizeof(T));
             incrementChunk(sizeof(T));
         } else {
             read(reinterpret_cast<data_type *>(&val), sizeof(T));
diff --git a/lang/c++/include/avro/buffer/detail/BufferDetail.hh 
b/lang/c++/include/avro/buffer/detail/BufferDetail.hh
index 5ef52a5fa8..30745008fd 100644
--- a/lang/c++/include/avro/buffer/detail/BufferDetail.hh
+++ b/lang/c++/include/avro/buffer/detail/BufferDetail.hh
@@ -20,6 +20,7 @@
 #define avro_BufferDetail_hh__
 
 #include <cassert>
+#include <cstring>
 #include <deque>
 #include <exception>
 #include <functional>
@@ -320,7 +321,7 @@ public:
         if (freeSpace_ && (sizeof(T) <= writeChunks_.front().freeSize())) {
             // fast path, there's enough room in the writeable chunk to just
             // straight out copy it
-            *(reinterpret_cast<T *>(writeChunks_.front().tellWritePos())) = 
val;
+            memcpy(writeChunks_.front().tellWritePos(), &val, sizeof(T));
             postWrite(sizeof(T));
         } else {
             // need to fixup chunks first, so use the regular memcpy

Reply via email to