-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core: fix configuration type cast issue on big endian systems #8904
base: master
Are you sure you want to change the base?
Conversation
Hi, @cosmo0920 @edsiper , could you please help to review this PR, it fixes the issues reported in #8828 |
@@ -649,10 +649,10 @@ int flb_config_map_set(struct mk_list *properties, struct mk_list *map, void *co | |||
} | |||
else if (m->type == FLB_CONFIG_MAP_TIME) { | |||
m_i_num = (int *) (base + m->offset); | |||
*m_i_num = m->value.val.s_num; | |||
*m_i_num = m->value.val.i_num; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value is stored in the first 4 byte of val
, get it using s_num will add 4 bytes of zero on the higher address in memory, this gives different result on big endian systems and little endian systems, this can be proved using the below code
#include <stdio.h>
#include <stddef.h> // Include this header for size_t
int main() {
printf("Size of size_t: %zu bytes\n", sizeof(size_t)); // 8
printf("Size of int: %zu bytes\n\n", sizeof(int)); // 4
int a[2] = {1, 0};
int *i_num = (int *)a;
printf("Value of i_num: %d\n\n", *i_num);
size_t *s_num = (size_t *)a;
printf("Value of s_num: %zu\n", *s_num);
printf("Cast s_num as int: %d\n", (int)(*s_num));
return 0;
}
The output of the code on x86(little endian system):
Size of size_t: 8 bytes
Size of int: 4 bytes
Value of i_num: 1
Value of s_num: 1
Cast s_num as int: 1
On s390s system(big endian):
Size of size_t: 8 bytes
Size of int: 4 bytes
Value of i_num: 1
Value of s_num: 4294967296
Cast s_num as int: 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The s_num 4294967296 in the output of big endian system equals to 1<<32
@@ -776,7 +776,7 @@ int flb_config_map_set(struct mk_list *properties, struct mk_list *map, void *co | |||
*m_d_num = atof(kv->val); | |||
} | |||
else if (m->type == FLB_CONFIG_MAP_BOOL) { | |||
m_bool = (char *) (base + m->offset); | |||
m_bool = (int *) (base + m->offset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assigning the value 1 to the byte indexed at base + m->offset
and read it combining with the 3 following bytes as int will lead to different result on big endian and little endian systems,
on big endian systems, the 4 byte number |01|00|00|00| equals to 16777216(1<<24), on little endian systems it equals to 1.
This can be verified by the code snippet below:
#include <stdio.h>
#include <stdbool.h>
int main() {
int a = 0;
char *p = (char*)(&a);
*p = 1;
printf("The value of a is now: %d\n", a);
int b;
int *p1 = (int*)(&b);
*p1 = 1;
printf("The value of b is now: %d\n", b);
return 0;
}
The output on x86(little endian system):
The value of a is now: 1
The value of b is now: 1
on s390x(big endian system):
The value of a is now: 16777216
The value of b is now: 1
Hi, @cosmo0920 @edsiper, could you please help to review this PR? I added 2 code snippet to show the issues. It fixes two types configuration failure issues that only appear on big endian systems,
|
Could you ensure DCO, that is, adding |
Signed-off-by: YingJie Fu <[email protected]>
Hi, @cosmo0920, could you please help to review again? I am from IBM and can assure DCO is complied, signed-off has been added to the commit. |
Hi, @cosmo0920, could you help to get this PR merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that this change should be nice. However, I didn't have BE byteorder systems. All of my having platforms are LE, i.e. x86_64 (Windows, Linux), aarch64 Linux on Chromebook and Windows on ARM64, and Linux on riscv64 . Before getting merged, should we confirm this PR effects on somewhere else of s390x systems on cloud?
Hi, @cosmo0920, the test log and the valgrind output in the PR description could help to double confirm this is done on s390x,
but if you really want to, you can use the LinuxONE Community Cloud. The usage is free for Open-Source Developers: |
@cosmo0920 This is a really important change for us, so we'd like to see it merged as soon as feasibly possible. Do you think the test log and /cc @edsiper @fujimotos @koleini @leonardo-albertovich @agup006 |
@cosmo0920, Did you get the s390x environment and try the PR? Is there a chance we can get this fix into v3.0.8? |
Addresses #8828
It fixes two types configuration failure issues that only appear on big endian systems,
rotate_wait
fortail
plugin.lowercase
insystemd
plugin.Enter
[N/A]
in the box, if an item is not applicable to your change.Testing
Before we can approve your change; please submit the following in a comment:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
ok-package-test
label to test for all targets (requires maintainer to do).Documentation
Backporting
Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.