Skip to content

Commit fa5d2c7

Browse files
committed
Use full time_t size (which is 64bit on 64bit architectures) for time
(Fixes# #11532) Signed-off-by: Dirk Müller <dirk@dmllr.de>
1 parent 405fed0 commit fa5d2c7

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

include/fluent-bit/flb_log_event.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
* Any other negative timestamp is considered invalid and will be skipped during decoding.
4545
* Encoders must respect this contract and only use -1/-2 for group markers.
4646
*/
47-
#define FLB_LOG_EVENT_NORMAL (int32_t) 0
48-
#define FLB_LOG_EVENT_GROUP_START (int32_t) -1
49-
#define FLB_LOG_EVENT_GROUP_END (int32_t) -2
47+
#define FLB_LOG_EVENT_NORMAL (time_t) 0
48+
#define FLB_LOG_EVENT_GROUP_START (time_t) -1
49+
#define FLB_LOG_EVENT_GROUP_END (time_t) -2
5050

5151
struct flb_log_event {
5252
msgpack_object *group_attributes;

src/flb_log_event_decoder.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ void flb_log_event_decoder_destroy(struct flb_log_event_decoder *context)
180180
int flb_log_event_decoder_decode_timestamp(msgpack_object *input,
181181
struct flb_time *output)
182182
{
183+
uint32_t packed_sec;
184+
183185
flb_time_zero(output);
184186

185187
if (input->type == MSGPACK_OBJECT_POSITIVE_INTEGER) {
@@ -194,13 +196,23 @@ int flb_log_event_decoder_decode_timestamp(msgpack_object *input,
194196
return FLB_EVENT_DECODER_ERROR_WRONG_TIMESTAMP_TYPE;
195197
}
196198

197-
output->tm.tv_sec =
198-
(int32_t) FLB_UINT32_TO_HOST_BYTE_ORDER(
199+
/* convert uint_32t style seconds to time_t style seconds */
200+
packed_sec = FLB_UINT32_TO_HOST_BYTE_ORDER(
199201
FLB_ALIGNED_DWORD_READ(
200202
(unsigned char *) &input->via.ext.ptr[0]));
201203

204+
if (packed_sec == (uint32_t) FLB_LOG_EVENT_GROUP_START) {
205+
output->tm.tv_sec = FLB_LOG_EVENT_GROUP_START;
206+
}
207+
else if (packed_sec == (uint32_t) FLB_LOG_EVENT_GROUP_END) {
208+
output->tm.tv_sec = FLB_LOG_EVENT_GROUP_END;
209+
}
210+
else {
211+
output->tm.tv_sec = (time_t) packed_sec;
212+
}
213+
202214
output->tm.tv_nsec =
203-
(int32_t) FLB_UINT32_TO_HOST_BYTE_ORDER(
215+
(time_t) FLB_UINT32_TO_HOST_BYTE_ORDER(
204216
FLB_ALIGNED_DWORD_READ(
205217
(unsigned char *) &input->via.ext.ptr[4]));
206218
}
@@ -313,7 +325,7 @@ int flb_log_event_decoder_next(struct flb_log_event_decoder *context,
313325
int result;
314326
int record_type;
315327
size_t previous_offset;
316-
int32_t invalid_timestamp;
328+
int64_t invalid_timestamp;
317329

318330
if (context == NULL) {
319331
return FLB_EVENT_DECODER_ERROR_INVALID_CONTEXT;
@@ -368,8 +380,8 @@ int flb_log_event_decoder_next(struct flb_log_event_decoder *context,
368380
* to avoid losing valid group metadata if corruption occurs mid-group.
369381
* Skip the record and continue processing.
370382
*/
371-
invalid_timestamp = (int32_t) event->timestamp.tm.tv_sec;
372-
flb_debug("[decoder] Invalid group marker timestamp (%d), skipping record. "
383+
invalid_timestamp = (int64_t) event->timestamp.tm.tv_sec;
384+
flb_debug("[decoder] Invalid group marker timestamp (%ld), skipping record. "
373385
"Group state preserved.", invalid_timestamp);
374386

375387
/* Increment recursion depth before recursive call */
@@ -457,22 +469,22 @@ int flb_log_event_decoder_next(struct flb_log_event_decoder *context,
457469

458470
int flb_log_event_decoder_get_record_type(struct flb_log_event *event, int32_t *type)
459471
{
460-
int32_t s;
472+
time_t s;
461473

462-
s = (int32_t) event->timestamp.tm.tv_sec;
474+
s = event->timestamp.tm.tv_sec;
463475

464-
if (s >= 0) {
465-
*type = FLB_LOG_EVENT_NORMAL;
466-
return 0;
467-
}
468-
else if (s == FLB_LOG_EVENT_GROUP_START) {
476+
if (s == FLB_LOG_EVENT_GROUP_START) {
469477
*type = FLB_LOG_EVENT_GROUP_START;
470478
return 0;
471479
}
472480
else if (s == FLB_LOG_EVENT_GROUP_END) {
473481
*type = FLB_LOG_EVENT_GROUP_END;
474482
return 0;
475483
}
484+
else if (s >= 0) {
485+
*type = FLB_LOG_EVENT_NORMAL;
486+
return 0;
487+
}
476488

477489
return -1;
478490
}

0 commit comments

Comments
 (0)