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 empty byte[] bug in EventSource #52602

Merged
merged 6 commits into from
May 13, 2021

Conversation

MihaZupan
Copy link
Member

#52092 switched from a for loop to Marshal.Copy when copying data to a byte[].

Since fixed will return a null ptr for empty arrays and custom event implementations may not have this guard against that, we end up calling Marshal.Copy(NULL, ... length: 0).

One such case was in NetEventSource.DumpBuffer.

This PR

cc: @karelz

@ghost
Copy link

ghost commented May 11, 2021

Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti
See info in area-owners.md if you want to be subscribed.

Issue Details

#52092 switched from a for loop to Marshal.Copy when copying data to a byte[].

Since fixed will return a null ptr for empty arrays and custom event implementations may not have this guard against that, we end up calling Marshal.Copy(NULL, ... length: 0).

One such case was in NetEventSource.DumpBuffer.

This PR

cc: @karelz

Author: MihaZupan
Assignees: -
Labels:

area-System.Diagnostics.Tracing

Milestone: 6.0.0

@MihaZupan

This comment has been minimized.

@MihaZupan
Copy link
Member Author

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@sywhang sywhang left a comment

Choose a reason for hiding this comment

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

@MihaZupan
Copy link
Member Author

Tests are hitting #52596

@MihaZupan MihaZupan closed this May 12, 2021
@MihaZupan MihaZupan reopened this May 12, 2021
@MihaZupan
Copy link
Member Author

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines +1838 to +1847
if (data->Size == 0)
{
decoded = Array.Empty<byte>();
}
else
{
var blob = new byte[data->Size];
Marshal.Copy(data->DataPointer, blob, 0, blob.Length);
decoded = blob;
}
Copy link
Member

@stephentoub stephentoub May 26, 2021

Choose a reason for hiding this comment

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

This would be simpler and safer as:

decoded = new Span<byte>((byte*)data->DataPointer, data->Size).ToArray();

Copy link
Member Author

@MihaZupan MihaZupan May 26, 2021

Choose a reason for hiding this comment

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

That is what I had used initially, but it sadly involves duplicating the logic under #if #else as EventSource is also being built standalone (no Span)

Copy link
Member

Choose a reason for hiding this comment

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

Why not reference the netstandard span package from the downlevel solution?

Either way, I don't think we should penalize the latest platform because of the source sharing.

Copy link
Member

Choose a reason for hiding this comment

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

@brianrob, we still maintain/ship the separate EventSource package? Who uses that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Either way, I don't think we should penalize the latest platform because of the source sharing.

100% agree with this.

Who uses that?

This periodically comes up (see: #32276 (comment)). This is building this package, which is used to ship EventSource features out-of-band for older framework releases. Download counts have been dwindling since 2015. The 5.0 version has ~320k downloads in 7 months.

Copy link
Member

@stephentoub stephentoub May 26, 2021

Choose a reason for hiding this comment

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

which is used to ship EventSource features out-of-band for older framework releases

Are we still adding new EventSource features it's important to be able to release in this vehicle? Can we just stop shipping new versions of it? If it's about bug fixes as Brian mentions in the linked comment, can we just treat it as servicing and fix bugs out of release/5.0?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm okay with moving that to a servicing life cycle. Brian has a better sense of what impact that would have though, so I would defer to his input before ripping it out.

CC @noahfalk

Copy link
Member

Choose a reason for hiding this comment

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

The EventSource package is really used for two things:

  1. Ship new features out-of-band for older frameworks.
  2. Ship bug fixes out-of-band for older frameworks.

The package only targets .NET Framework, so anything for .NET Core would just go through the standard servicing process. It's not clear to me that we're adding new features to EventSource at a rate that really requires the package - for me, the question is really whether or not we need a relief valve to be able to fix issues on .NET Framework. If we can do that through a servicing release, then that's fine, but I worry that .NET 5 will only be supported for so long and then we lose the infrastructure and shipping support for this. Over time, as we move folks towards .NET Core, this package becomes less and less important, but I don't think we're in a place where we'll be ready in a year or two to just stop producing the package, even through servicing.

Copy link
Member

Choose a reason for hiding this comment

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

a relief valve to be able to fix issues on .NET Framework

To make sure I understand, this doesn't actually unify with what's in .NET Framework, right? Someone has to explicitly switch from using the EventSource in .NET Framework to this differently namespaced type in the OOB?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's right - it does not unify. Someone will have to explicitly consume the NuGet package. The namespace is also different - Microsoft.Diagnostics.Tracing instead of System.Diagnostics.Tracing.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test failure System.Net.Sockets.Tests.LoggingTest.EventSource_EventsRaisedAsExpected
6 participants