Skip to content

AVRO-4360: [C++] Fix binary floating-point byte order - #4043

Merged
Fokko merged 1 commit into
apache:mainfrom
manuzhang:fix/cpp-float-double-endian-regression
Oct 14, 2026
Merged

Fokko merged 1 commit into
apache:mainfrom
manuzhang:fix/cpp-float-double-endian-regression

Conversation

@manuzhang

@manuzhang manuzhang commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

What is the purpose of the change

Avro C++ copies native memory bytes when encoding and decoding float/double values. On big-endian hosts such as s390x, encoding float 1.0 produces 3f 80 00 00 instead of the required 00 00 80 3f, and decoding valid little-endian Avro bytes returns the wrong value.

Normalize the four binary floating-point methods to little-endian byte order while preserving raw IEEE 754 bits.

Fixes AVRO-4360.

Verifying this change

Added independent golden-byte checks for float and double encoding and decoding, covering signed zero, finite and subnormal limits, infinities, and quiet NaN payloads with stream chunk sizes of 1, 3, and 16 bytes.

Local validation on the exact published source:

  • Full CodecTests suite passes on macOS and Linux ARM64: 852 test cases and 103,659 assertions on each.
  • GCC 14 s390x cross-build under QEMU: all 132 new assertions pass; the original codec fails 120 of the same 132 assertions.
  • Patch applicability with strict whitespace checks and formatting of changed regions pass.

The s390x result is emulated, rather than a physical s390x run.

Documentation

  • Does this pull request introduce a new feature? No; it fixes binary-format compliance.
  • Documentation changes: not applicable.

@github-actions github-actions Bot added the C++ Pull Requests for C++ binding label Oct 13, 2026
Use the little-endian IEEE 754 wire format required by Avro when
encoding and decoding floats and doubles on big-endian hosts.
Add independent wire-byte regressions for signed zero, finite limits,
infinities and NaN payloads across fragmented streams.

Co-authored-by: Codex <codex@openai.com>
@manuzhang
manuzhang force-pushed the fix/cpp-float-double-endian-regression branch from ec170ca to 1687f59 Compare October 13, 2026 04:48
@manuzhang manuzhang changed the title [C++] Fix binary floating-point byte order AVRO-4360: [C++] Fix binary floating-point byte order Oct 13, 2026
@manuzhang
manuzhang marked this pull request as ready for review October 13, 2026 04:48

@wgtmac wgtmac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@wgtmac

wgtmac commented Oct 13, 2026

Copy link
Copy Markdown
Member

Could you help review this? @Fokko @thiru-mg @iemejia @RyanSkraba

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me! Do we know if this is the case as well for other types? For example, Decimal?

@manuzhang

Copy link
Copy Markdown
Member Author

As for decimal, it's the application handling the endian and Avro C++ just preserves bytes. No other types as I've checked.

@Fokko

Fokko commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@manuzhang Got it, thanks for checking. Moving this forward 👍

@Fokko
Fokko merged commit 3a207fa into apache:main Oct 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C++ Pull Requests for C++ binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants