From 8584d7cd5ae101dcc9b63d0e04522c8fd3524187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ferreira=20Gonz=C3=A1lez?= Date: Mon, 18 May 2026 16:19:05 +0200 Subject: [PATCH 1/5] Refs #24365: Fix UB in calculate_array_serialized_size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Ferreira González --- include/fastcdr/CdrSizeCalculator.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/fastcdr/CdrSizeCalculator.hpp b/include/fastcdr/CdrSizeCalculator.hpp index 9b1caea5..ef7782e9 100644 --- a/include/fastcdr/CdrSizeCalculator.hpp +++ b/include/fastcdr/CdrSizeCalculator.hpp @@ -1065,7 +1065,11 @@ class CdrSizeCalculator size_t num_elements, size_t& current_alignment) { - return calculate_array_serialized_size(data->data(), num_elements * data->size(), current_alignment); + if (0 == num_elements) + { + return 0; + } + return calculate_array_serialized_size(data->data(), num_elements * _N, current_alignment); } /*! From f889a8b592bae785060cfa66e69d78a99ca6f4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ferreira=20Gonz=C3=A1lez?= Date: Tue, 19 May 2026 07:37:22 +0200 Subject: [PATCH 2/5] Refs #24365: Fix UB in serialize array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Ferreira González --- include/fastcdr/Cdr.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/fastcdr/Cdr.h b/include/fastcdr/Cdr.h index a582e6a2..d9007eb0 100644 --- a/include/fastcdr/Cdr.h +++ b/include/fastcdr/Cdr.h @@ -2973,6 +2973,10 @@ class Cdr const std::array<_T, _Size>* array_t, size_t num_elements) { + if (num_elements == 0) + { + return *this; + } return serialize_array(array_t->data(), num_elements * array_t->size()); } From 2cb501caf06513e45b912c07fe1da0dc80034fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ferreira=20Gonz=C3=A1lez?= Date: Tue, 19 May 2026 09:15:38 +0200 Subject: [PATCH 3/5] Refs #24365: Unrelated Uncrustify MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Ferreira González --- include/fastcdr/Cdr.h | 4 ++-- include/fastcdr/CdrSizeCalculator.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/fastcdr/Cdr.h b/include/fastcdr/Cdr.h index d9007eb0..0ca56747 100644 --- a/include/fastcdr/Cdr.h +++ b/include/fastcdr/Cdr.h @@ -720,7 +720,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to encode into a buffer * position that exceeds the internal memory size. */ - template + template Cdr& serialize( const fixed_string& value) { @@ -1787,7 +1787,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to decode from a buffer * position that exceeds the internal memory size. */ - template + template Cdr& deserialize( fixed_string& value) { diff --git a/include/fastcdr/CdrSizeCalculator.hpp b/include/fastcdr/CdrSizeCalculator.hpp index ef7782e9..4e0125d2 100644 --- a/include/fastcdr/CdrSizeCalculator.hpp +++ b/include/fastcdr/CdrSizeCalculator.hpp @@ -480,7 +480,7 @@ class CdrSizeCalculator * @param[inout] current_alignment Current alignment in the encoding. * @return Encoded size of the instance. */ - template + template size_t calculate_serialized_size( const fixed_string& data, size_t& current_alignment) From 1de8525aa98d29eab5f96ce9f4f614eb0509279c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ferreira=20Gonz=C3=A1lez?= Date: Tue, 19 May 2026 09:30:08 +0200 Subject: [PATCH 4/5] Refs #24365: Revision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Ferreira González --- include/fastcdr/Cdr.h | 10 +++++++++- include/fastcdr/CdrSizeCalculator.hpp | 2 +- include/fastcdr/FastCdr.h | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/fastcdr/Cdr.h b/include/fastcdr/Cdr.h index 0ca56747..b2389785 100644 --- a/include/fastcdr/Cdr.h +++ b/include/fastcdr/Cdr.h @@ -2973,7 +2973,7 @@ class Cdr const std::array<_T, _Size>* array_t, size_t num_elements) { - if (num_elements == 0) + if (num_elements == 0 || array_t == nullptr) { return *this; } @@ -2992,6 +2992,10 @@ class Cdr std::array<_T, _Size>* array_t, size_t num_elements) { + if (num_elements == 0 || array_t == nullptr) + { + return *this; + } return deserialize_array(array_t->data(), num_elements * array_t->size()); } @@ -3009,6 +3013,10 @@ class Cdr size_t num_elements, Endianness endianness) { + if (num_elements == 0 || array_t == nullptr) + { + return *this; + } return deserialize_array(array_t->data(), num_elements * array_t->size(), endianness); } diff --git a/include/fastcdr/CdrSizeCalculator.hpp b/include/fastcdr/CdrSizeCalculator.hpp index 4e0125d2..c46d9854 100644 --- a/include/fastcdr/CdrSizeCalculator.hpp +++ b/include/fastcdr/CdrSizeCalculator.hpp @@ -1065,7 +1065,7 @@ class CdrSizeCalculator size_t num_elements, size_t& current_alignment) { - if (0 == num_elements) + if (num_elements == 0 || data == nullptr) { return 0; } diff --git a/include/fastcdr/FastCdr.h b/include/fastcdr/FastCdr.h index 4cce3920..bf848b9a 100644 --- a/include/fastcdr/FastCdr.h +++ b/include/fastcdr/FastCdr.h @@ -2047,6 +2047,10 @@ class Cdr_DllAPI FastCdr const std::array<_T, _Size>* array_t, size_t num_elements) { + if (num_elements == 0 || array_t == nullptr) + { + return *this; + } return serialize_array(array_t->data(), num_elements * array_t->size()); } @@ -2062,6 +2066,10 @@ class Cdr_DllAPI FastCdr std::array<_T, _Size>* array_t, size_t num_elements) { + if (num_elements == 0 || array_t == nullptr) + { + return *this; + } return deserialize_array(array_t->data(), num_elements * array_t->size()); } From 38e7db9c02970d535cb4f764c74570c1a56e4c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ferreira=20Gonz=C3=A1lez?= Date: Tue, 19 May 2026 09:31:39 +0200 Subject: [PATCH 5/5] Refs #24365: Unrelated Uncrustify FastCdr.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Ferreira González --- include/fastcdr/FastCdr.h | 42 ++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/include/fastcdr/FastCdr.h b/include/fastcdr/FastCdr.h index bf848b9a..d96f989d 100644 --- a/include/fastcdr/FastCdr.h +++ b/include/fastcdr/FastCdr.h @@ -655,7 +655,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -702,7 +703,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -736,7 +738,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -783,7 +786,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -804,7 +808,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -825,7 +830,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -850,7 +856,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1306,7 +1313,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1353,7 +1361,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1387,7 +1396,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1437,7 +1447,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1458,7 +1469,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1479,7 +1491,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1503,7 +1516,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*!