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

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

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

bpint
Copy link
Contributor

@bpint bpint 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

`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,
rabbitmq#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.
@pivotal-cla
Copy link

@bpint Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-cla
Copy link

@bpint Thank you for signing the Contributor License Agreement!

@michaelklishin michaelklishin self-assigned this Dec 4, 2024
@michaelklishin michaelklishin changed the title Fix crash caused by mishandling of non-ascii amqp_error explanation Fixes an exception in AMQP 0-9-1 exception (error) generator when input data includes non-ASCII characters Dec 4, 2024
michaelklishin added a commit that referenced this pull request Dec 4, 2024
@michaelklishin
Copy link
Member

Thank you, @bpint!

I have re-submitted as #12889 so that CI has access to all the relevant secrets. Plus added one more test case because it was used in #12874.

@michaelklishin
Copy link
Member

#12889 is in.

@bpint in some 8-10 minutes a new 4.1.0 preview release will be produced and made available.
You can get the package you need there and run it through the same test you've used on 4.0.4.

4.0.5 previews will have to wait until #12890 is merged but will show up in the same repository.

@michaelklishin
Copy link
Member

Curiously, one of the workflows failed for the first time in weeks, for a reason that has nothing to do with this PR. I have restarted it.

@michaelklishin
Copy link
Member

There you go, 4.1.0-alpha.28b0b05b.

@bpint
Copy link
Contributor Author

bpint commented Dec 4, 2024

There you go, 4.1.0-alpha.28b0b05b.

@michaelklishin thanks! i have tried the following shovel. it declared 2 non-existing queues and work well.

{
    "ack-mode": "on-confirm",
    "dest-add-forward-headers": false,
    "dest-protocol": "amqp091",
    "dest-queue": "кролик 🐰",
    "dest-uri": "amqp://",
    "src-delete-after": "never",
    "src-protocol": "amqp091",
    "src-queue": "non_ascii_name_😍_你好",
    "src-uri": "amqp://"
}

screenshot1 2024-12-04 13-39-41
screenshot2 2024-12-04 13-39-28

2024-12-04 13:36:18.820917+08:00 [error] <0.1091.0> Channel error on connection <0.1071.0> (<port-5672@zen.1733290540.1071.0>, vhost: '/', user: 'none'), channel 2:
2024-12-04 13:36:18.820917+08:00 [error] <0.1091.0> operation queue.declare caused a channel exception not_found: no queue 'кролик 🐰' in vhost '/'
2024-12-04 13:36:18.828192+08:00 [error] <0.1115.0> Channel error on connection <0.1053.0> (<port-5672@zen.1733290540.1053.0>, vhost: '/', user: 'none'), channel 2:
2024-12-04 13:36:18.828192+08:00 [error] <0.1115.0> operation queue.declare caused a channel exception not_found: no queue 'non_ascii_name_😍_你好' in vhost '/'

@michaelklishin
Copy link
Member

Excellent. 4.0.5 will ship with this change around December 20th (give or take a couple of days).

@bpint bpint deleted the fix-unicode-mishandling-crash branch December 4, 2024 06:05
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