Skip to content

Encode AMQP 1.0 arrays of zero-octet elements as opaque values#16994

Merged
michaelklishin merged 1 commit into
mainfrom
amqp-parser
Jul 21, 2026
Merged

Encode AMQP 1.0 arrays of zero-octet elements as opaque values#16994
michaelklishin merged 1 commit into
mainfrom
amqp-parser

Conversation

@ansd

@ansd ansd commented Jul 21, 2026

Copy link
Copy Markdown
Member

What?

The AMQP 1.0 binary parser (amqp10_binary_parser) decoded an array whose element constructor has a zero-octet wire encoding (null, true, false, uint0, ulong0, list0 - wire codes 0x40-0x45) by expanding it into a full Erlang list, one term per element, via lists:duplicate/2. It now instead represents such an array as an opaque value ({as_is, TypeCode, Bin}), the same representation already used for decimal and NaN/Infinity values that RabbitMQ has no need to interpret further.

Why

For this class of array, the element count is carried in a small, fixed-size wire encoding, while the previous implementation allocated one term per element when decoding it. This meant the memory needed to hold the decoded value had no relationship to the size of the input that produced it. Representing the value opaquely removes that mismatch entirely, rather than merely capping it, and keeps the parser consistent with how it already treats other value kinds it does not need to interpret.

Supersedes #16986

 ## What?

The AMQP 1.0 binary parser (amqp10_binary_parser) decoded an array
whose element constructor has a zero-octet wire encoding (null, true,
false, uint0, ulong0, list0 - wire codes 0x40-0x45) by expanding it
into a full Erlang list, one term per element, via lists:duplicate/2.
It now instead represents such an array as an opaque value ({as_is,
TypeCode, Bin}), the same representation already used for decimal and
NaN/Infinity values that RabbitMQ has no need to interpret further.

 ## Why

For this class of array, the element count is carried in a small,
fixed-size wire encoding, while the previous implementation allocated
one term per element when decoding it. This meant the memory needed to
hold the decoded value had no relationship to the size of the input
that produced it. Representing the value opaquely removes that
mismatch entirely, rather than merely capping it, and keeps the parser
consistent with how it already treats other value kinds it does not
need to interpret.
@ansd ansd added this to the 4.4.0 milestone Jul 21, 2026
@ansd ansd self-assigned this Jul 21, 2026
@ansd
ansd marked this pull request as ready for review July 21, 2026 16:49
@mergify

mergify Bot commented Jul 21, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@lhoguin lhoguin 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.

If you don't need them then yes not decoding them is the way to go.

@michaelklishin michaelklishin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is an elegant solution that still addresses the issue at hand. I have tried with a 130M element modification across thousands of collections and it does work as expected.

@michaelklishin
michaelklishin merged commit 195e549 into main Jul 21, 2026
188 checks passed
@michaelklishin
michaelklishin deleted the amqp-parser branch July 21, 2026 23:50
michaelklishin added a commit that referenced this pull request Jul 22, 2026
Encode AMQP 1.0 arrays of zero-octet elements as opaque values (backport #16994)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants