-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix ByteString.Copy
when requested length is zero
#6749
Conversation
There was a problem hiding this 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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Detailed my changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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):