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

Fix ByteString.Copy when requested length is zero #6749

Conversation

Aaronontheweb
Copy link
Member

@Aaronontheweb Aaronontheweb commented May 9, 2023

Changes

Fixes #6748 - underlying issue was really a ByteString.Copy bug that occurs when the requested length is zero and the buffer length is zero. This is a perfectly legal bounds check, but an unhandled edge case. We now no-op it properly.

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

Copy link
Member Author

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Detailed my changes

ConsumerController.SequencedMessage<ZeroLengthSerializer.TestMsg>.FromChunkedMessage(ProducerId, 1 + i, c, i == 0, false,
producerControllerProbe)).ToList();
consumerController.Tell(seqMessages1.First());
(await consumerProbe.ExpectMsgAsync<ConsumerController.Delivery<ZeroLengthSerializer.TestMsg>>()).Message.Should().Be(ZeroLengthSerializer.TestMsg.Instance);
Copy link
Member Author

Choose a reason for hiding this comment

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

Reproduction spec would fail here previously and record the same error found in #6749

/// <summary>
/// For testing purposes
/// </summary>
public sealed class ZeroLengthSerializer : SerializerWithStringManifest
Copy link
Member Author

Choose a reason for hiding this comment

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

Serializer to replicate the error

@@ -539,6 +539,7 @@ public ByteString Concat(ByteString other)
/// <returns>TBD</returns>
public int CopyTo(byte[] buffer, int index, int count)
{
if(buffer.Length == 0 && count == 0) return 0; // edge case for no-copy
Copy link
Member Author

Choose a reason for hiding this comment

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

Added the same bounds check to all three implementations of the CopyTo method.

Copy link
Member Author

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Detailed my changes

Copy link
Contributor

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

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

LGTM

@Aaronontheweb Aaronontheweb merged commit d783933 into akkadotnet:dev May 10, 2023
@Aaronontheweb Aaronontheweb deleted the fix-6748-ConsumerController-0-length-chunk branch May 10, 2023 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Akka.Delivery: ConsumerController throws ArgumentOutOfRange when decoding zero-length chunk
2 participants