Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public int FillWriterWithMessages(ref DataStreamWriter writer)
{
writer.WriteInt(messageLength);

var messageOffset = HeadIndex + reader.GetBytesRead();
var messageOffset = reader.GetBytesRead();
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

If you look above here, there's readerOffset = HeadIndex. This was changed in #2224 from readerOffset = 0 because reader was changed from being a slice of m_data to containing all of m_data and reading from that offset. The return value of GetBytesRead() here already includes HeadIndex, so this results in HeadIndex being applied twice when calculating messageOffset.

When HeadIndex is 0 that has no effect, but when the queue gets filled more, it starts resulting in things being skipped over, data being corrupted, and - sometimes - data from completely outside the stream (i.e., garbage data) being copied into the stream.

WriteBytes(ref writer, (byte*)m_Data.GetUnsafePtr() + messageOffset, messageLength);

writerAvailable -= sizeof(int) + messageLength;
Expand Down