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

simplify WriteShortstr #845

Merged
merged 1 commit into from
May 24, 2020

Conversation

bollhals
Copy link
Contributor

Proposed Changes

Simplifying write of string values. GetBytes returns the number of bytes written, so there is no need to precalculate the length.

Types of Changes

  • Bug fix (non-breaking change which fixes issue #NNNN)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause an observable behavior change in existing systems)
  • Documentation improvements (corrections, new content, etc)
  • Cosmetic change (whitespace, formatting, etc)

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)
  • All tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in related repositories

Further Comments

Question: There is a bug in the code (before this and also after this) that if you write a string resulting in more than 255 bytes, the length variable (byte) will be cut off and the resulting deserialized value will be different from the source. Shall I open an issue for this?

@michaelklishin
Copy link
Member

Thank you!

@michaelklishin michaelklishin merged commit fb8e1f2 into rabbitmq:master May 24, 2020
michaelklishin added a commit that referenced this pull request May 24, 2020
simplify WriteShortstr

(cherry picked from commit fb8e1f2)
@bollhals
Copy link
Contributor Author

bollhals commented May 24, 2020

Question: There is a bug in the code (before this and also after this) that if you write a string resulting in more than 255 bytes, the length variable (byte) will be cut off and the resulting deserialized value will be different from the source.

Shall I open an issue for this or is this "as designed"?

@bollhals bollhals deleted the simplify.write.string branch May 24, 2020 19:35
@stebet
Copy link
Contributor

stebet commented May 25, 2020

An AMQP shortstr value can only contain 256 bytes: https://www.rabbitmq.com/amqp-0-9-1-reference.html#domain.shortstr

@bollhals
Copy link
Contributor Author

Yes, that I understand, but the current code does the following for payload all 'A':

real length length payload
255 255 65, 65, ... (255 times)
256 0 65, 65, ... (256 times)

So when you read it back, it reads wrong values (due to the wrong ones sent).

There is nowhere a prevention built in to not being able to send more than 255 chars.

@michaelklishin
Copy link
Member

We should fail early and visibly so yes @bollhals, this is worth changing, even though this is how the protocol is designed and not really a bug.

@michaelklishin
Copy link
Member

Backported to 6.x.

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.

4 participants