Skip to content

Fixes an exception in AMQP 0-9-1 exception (error) generator when input data includes non-ASCII characters (backport #12888) #12891

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

Closed
wants to merge 1 commit into from

Conversation

mergify[bot]
Copy link

@mergify mergify bot commented Dec 4, 2024

Proposed Changes

rabbit_binary_generator:map_exception/3 will crash when there are unicode characters in the explanation field of Reason#amqp_error parameter. The explanation string (list) is assumed to be ascii, with each character/member in the range of a byte. Any unicode characters in the string will trigger badarg crash of list_to_binary/1 in rabbit_binary_generator:amqp_exception_explanation/2.

Amqp091 shovel crash due to this is reported, #12874
When a queue as shovel source/destination does not exist, and its name contains non-ascii characters, the explanation of amqp_error will be like no queue non_ascii_name_😍 in vhost /. It will subsequently crash and even affect management console.

To fix this, unicode:characters_to_binary/1 is used instead of list_to_binary/1, and unicode-safe truncation of long explanation with io_lib:format/3 chars_limit replaces direct bytes truncation.

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

Checklist

Put an x in the boxes that apply.
You can also fill these out after creating the PR.
If you're unsure about any of them, don't hesitate to ask on the mailing list.
We're here to help!
This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING.md document
  • I have signed the CA (see https://cla.pivotal.io/sign/rabbitmq)
  • I have added tests that prove my fix is effective or that my feature works
  • All tests pass locally with my changes
  • If relevant, I have added necessary documentation to https://github.com/rabbitmq/rabbitmq-website
  • If relevant, I have added this change to the first version(s) in release-notes that I expect to introduce it

This is an automatic backport of pull request #12888 done by [Mergify](https://mergify.com).

`rabbit_binary_generator:map_exception/3` will crash when there are
unicode characters in the `explaination` field of `Reason#amqp_error`
parameter. The explaination string (list) is assumed to be ascii, with
each character/member in the range of a byte. Any unicode characters
in the string will trigger `badarg` crash of `list_to_binary/1` in
`rabbit_binary_generator:amqp_exception_explanation/2`.

Amqp091 shovel crash due to this is reported,
https://github.com/rabbitmq/rabbitmq-server/discussions/12874
When a queue as shovel source/destination does not exist, and its
name contains non-ascii characters, the explaination of amqp_error
will be like `no queue non_ascii_name_😍 in vhost /`. It will
subsequently crash and even affect management console.

To fix this, `unicode:characters_to_binary/1` is used instead of
`list_to_binary/1`, and unicode-safe truncation of long explaination
with `io_lib:format/3` chars_limit replaces direct bytes truncation.

(cherry picked from commit ee41983)
@michaelklishin
Copy link
Collaborator

#12890

@michaelklishin michaelklishin deleted the mergify/bp/v4.0.x/pr-12888 branch January 13, 2025 04:21
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.

2 participants