Skip to content
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

pack: do not multiply out_size by realloc_size #9193

Merged
merged 2 commits into from
Aug 13, 2024

Conversation

braydonk
Copy link
Contributor

@braydonk braydonk commented Aug 12, 2024

In flb_msgpack_raw_to_json_sds, when the buffer is reallocated it calls flb_sds_increase. This increases the length by adding the len argument to the length and reallocating the sds object. After doing this, the out_size is multiplied by realloc_size. This does not match reality, as what happened in the reallocation was additive not multiplicative. This commit corrects the inconsistency.

Fixes #9192.
Fixes #8993.


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:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

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.

In `flb_msgpack_raw_to_json_sds`, when the buffer is reallocated it
calls `flb_sds_increase`. This increases the length by adding the `len`
argument to the length and reallocating the sds object. After doing
this, the `out_size` is multiplied by `realloc_size`. This does not
match reality, as what happened in the reallocation was additive not
multiplicative. This commit corrects the inconsistency.

Signed-off-by: braydonk <[email protected]>
src/flb_pack.c Outdated
@@ -810,7 +810,7 @@ flb_sds_t flb_msgpack_raw_to_json_sds(const void *in_buf, size_t in_size)
tmp_buf = flb_sds_increase(out_buf, realloc_size);
if (tmp_buf) {
out_buf = tmp_buf;
out_size *= realloc_size;
out_size += realloc_size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. what about to setting out_size with flb_sds_alloc() ?

https://github.com/fluent/fluent-bit/blob/master/include/fluent-bit/flb_sds.h#L67-L70

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 087ccda. Tested and it seems to work as expected.

@edsiper edsiper merged commit fa46ed9 into fluent:master Aug 13, 2024
41 of 42 checks passed
@edsiper
Copy link
Member

edsiper commented Aug 13, 2024

thank you

@braydonk braydonk deleted the fix_json_realloc branch August 13, 2024 15:47
ridwanmsharif added a commit to GoogleCloudPlatform/ops-agent that referenced this pull request Aug 14, 2024
This change picks up this chage from Fluent Bit:
fluent/fluent-bit#9193
edsiper pushed a commit that referenced this pull request Aug 14, 2024
In `flb_msgpack_raw_to_json_sds`, when the buffer is reallocated it calls `flb_sds_increase`. This increases the length by adding the `len` argument to the length and reallocating the sds object. After doing this, the `out_size` is multiplied by `realloc_size`. This does not match reality, as what happened in the reallocation was additive not multiplicative. This commit corrects the inconsistency.

Signed-off-by: braydonk <[email protected]>
ridwanmsharif pushed a commit to ridwanmsharif/fluent-bit that referenced this pull request Aug 14, 2024
In `flb_msgpack_raw_to_json_sds`, when the buffer is reallocated it calls `flb_sds_increase`. This increases the length by adding the `len` argument to the length and reallocating the sds object. After doing this, the `out_size` is multiplied by `realloc_size`. This does not match reality, as what happened in the reallocation was additive not multiplicative. This commit corrects the inconsistency.

Signed-off-by: braydonk <[email protected]>
ridwanmsharif added a commit to GoogleCloudPlatform/ops-agent that referenced this pull request Aug 14, 2024
braydonk added a commit that referenced this pull request Aug 14, 2024
In `flb_msgpack_raw_to_json_sds`, when the buffer is reallocated it calls `flb_sds_increase`. This increases the length by adding the `len` argument to the length and reallocating the sds object. After doing this, the `out_size` is multiplied by `realloc_size`. This does not match reality, as what happened in the reallocation was additive not multiplicative. This commit corrects the inconsistency.

Signed-off-by: braydonk <[email protected]>
ridwanmsharif added a commit to GoogleCloudPlatform/ops-agent that referenced this pull request Aug 14, 2024
ridwanmsharif added a commit to GoogleCloudPlatform/ops-agent that referenced this pull request Aug 15, 2024
This change picks up this chage from Fluent Bit:
fluent/fluent-bit#9193

Related bug: b/359600424
ridwanmsharif added a commit to GoogleCloudPlatform/ops-agent that referenced this pull request Aug 15, 2024
This change picks up this chage from Fluent Bit:
fluent/fluent-bit#9193

Related bug: b/359600424
AndrewChubatiuk pushed a commit to AndrewChubatiuk/fluent-bit that referenced this pull request Sep 24, 2024
In `flb_msgpack_raw_to_json_sds`, when the buffer is reallocated it calls `flb_sds_increase`. This increases the length by adding the `len` argument to the length and reallocating the sds object. After doing this, the `out_size` is multiplied by `realloc_size`. This does not match reality, as what happened in the reallocation was additive not multiplicative. This commit corrects the inconsistency.

Signed-off-by: braydonk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants