Skip to content

Commit

Permalink
log_event_decoder: updated code to use aligned memory reads
Browse files Browse the repository at this point in the history
This will not change the underlying code for 99.9% of the users,
however, when specifically enabled it through the FLB_ENFORCE_ALIGNMENT
feature flag, FLB_ALIGNED_DWORD_READ will issue four BYTE sized reads
instead of a single DWORD sized read to ensure that memory access is
aligned.

Signed-off-by: Leonardo Alminana <leonardo.alminana@chronosphere.io>
  • Loading branch information
leonardo-albertovich authored and edsiper committed Aug 9, 2024
1 parent 7f03748 commit bec6034
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/flb_log_event_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <fluent-bit/flb_log_event_decoder.h>
#include <fluent-bit/flb_byteswap.h>
#include <fluent-bit/flb_compat.h>

static int create_empty_map(struct flb_log_event_decoder *context) {
msgpack_packer packer;
Expand Down Expand Up @@ -179,8 +180,15 @@ int flb_log_event_decoder_decode_timestamp(msgpack_object *input,
return FLB_EVENT_DECODER_ERROR_WRONG_TIMESTAMP_TYPE;
}

output->tm.tv_sec = (int32_t) FLB_BSWAP_32(*((uint32_t *) &input->via.ext.ptr[0]));
output->tm.tv_nsec = (int32_t) FLB_BSWAP_32(*((uint32_t *) &input->via.ext.ptr[4]));
output->tm.tv_sec =
(int32_t) FLB_BSWAP_32(
FLB_ALIGNED_DWORD_READ(
(unsigned char *) &input->via.ext.ptr[0]));

output->tm.tv_nsec =
(int32_t) FLB_BSWAP_32(
FLB_ALIGNED_DWORD_READ(
(unsigned char *) &input->via.ext.ptr[4]));
}
else {
return FLB_EVENT_DECODER_ERROR_WRONG_TIMESTAMP_TYPE;
Expand Down

0 comments on commit bec6034

Please sign in to comment.