Skip to content

Conversation

Neofish22
Copy link

@Neofish22 Neofish22 commented Sep 18, 2025

Commit message:

The Floating Point Exception (FPE) FE_DIVBYZERO is flagged in rd_hdr_histogram_new when log2() is called with 0. This is done in rd_avg_init numerous times, some of which cannot be disabled in recent versions.

Consumers of librdkakfa may enable the raising of exceptions when FPEs occur, including FE_DIVBYZERO, which causes the function to fail.

It is reasonable for the callers of rd_hdr_histogram_new to pass 0 for the minValue parameter, and the intention of the calculation of unitMagnitude is also reasonable. As such, fixing the maths there is the correct approach. unitMagnitude being 0 in this case is an apt choice based on how log2(n) works for n near 0, and that the caluclation already minimises to 0.

A simple test was included that resets the flags, runs the offending function, and observes the new set flags. Appropriately, it fails before the fix, and passes after.

Description

First time doing a Pull Request on an open source project so please bear with me. :) Fixes #4949

I believe I have followed the contributing guidelines correctly; I have:

  • Read the contributing guidelines and code of conduct.
  • Followed the style guide and run make style-check-changed on the source file I changed and the source file I added.
  • Added a test.
  • Updated CHANGELOG.md.
  • Run make release-test. (TODO - I need to install trivup for that).

Potential issue in build config

One potential issue is that I had to modify the build process to link test-runner with -lrdkafka-static because it did not find the definition for rd_hdr_histogram_new. I assume this is something wrong with my build configuration, but if not we will need to do something to rectify it.

@confluent-cla-assistant
Copy link

confluent-cla-assistant bot commented Sep 18, 2025

🎉 All Contributor License Agreements have been signed. Ready to merge.
✅ Neofish22
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

…4949)

The Floating Point Exception (FPE) `FE_DIVBYZERO` is flagged in
`rd_hdr_histogram_new` when `log2()` is called with `0`. This is done in
`rd_avg_init` numerous times, some of which cannot be disabled in
recent versions.

Consumers of librdkakfa may enable the raising of exceptions when FPEs
occur, including `FE_DIVBYZERO`, which causes the function to fail.

It is reasonable for the callers of `rd_hdr_histogram_new` to pass `0`
for the `minValue` parameter, and the intention of the calculation of
`unitMagnitude` is also reasonable. As such, fixing the maths there is
the correct approach. `unitMagnitude` being `0` in this case is an apt
choice based on how log2(n) works for n near `0`, and that the
caluclation already minimises to `0`.

A simple test was included that resets the flags, runs the offending
function, and observes the new set flags. Appropriately, it fails
before the fix, and passes after.
@Neofish22 Neofish22 force-pushed the bugfix/4949-fpe-in-rd_hdr_histogram_new branch from be57f18 to 50f3850 Compare September 18, 2025 12:44
@Neofish22
Copy link
Author

Was unable to get trivup to work correctly, will try again as soon as I can (most likely next week; business trip).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Divide-by-zero in rd_hdr_histogram_new()
1 participant