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

Add additional exclusions for dependency collection #6282

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
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 @@ -176,15 +176,19 @@ private static bool IsHexChar(char c)

private static bool IsZeroVersionAssemblyPattern(string assemblyName)
{
return assemblyName.Length == 8
&& IsBase32Char(assemblyName[0])
&& IsBase32Char(assemblyName[1])
&& IsBase32Char(assemblyName[2])
&& IsBase32Char(assemblyName[3])
&& IsBase32Char(assemblyName[4])
&& IsBase32Char(assemblyName[5])
&& IsBase32Char(assemblyName[6])
&& IsBase32Char(assemblyName[7]);
// e.g.
// 454845b558934321ad350977dd095960
// akkynf62
return (assemblyName.Length == 8
&& IsBase32Char(assemblyName[0])
&& IsBase32Char(assemblyName[1])
&& IsBase32Char(assemblyName[2])
&& IsBase32Char(assemblyName[3])
&& IsBase32Char(assemblyName[4])
&& IsBase32Char(assemblyName[5])
&& IsBase32Char(assemblyName[6])
&& IsBase32Char(assemblyName[7]))
|| (assemblyName.Length == 32 && IsHexString(assemblyName, 0));
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of something like assemblyName.Length >= 16? I'm thinking after a certain number of characters, if they are all hexadecimal digits, then the risk of false positives like Cafe.dll or Beef.dll is very low. Just trying to avoid having to come back and add other lengths aside from 32 later.

Copy link
Member

Choose a reason for hiding this comment

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

Or >= 32 if you think 16 is not enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I toyed with that. I think 16+ is almost certainly going to be ok, but will use 32 for now, just for safety. In reality I wonder if we even need this check at all for Version = 0.0.0.0 🤷‍♂️ Whatever we do, there's going to be a certain amount of whackamole. But I guess we're unlikely to have ABadCafeFedDeafBeesBeef.dll 😄

Suggested change
|| (assemblyName.Length == 32 && IsHexString(assemblyName, 0));
|| (assemblyName.Length >= 32 && IsHexString(assemblyName, 0));

}

private static bool IsBase32Char(char c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,24 @@ public void DoesNotHaveChangesWhenAssemblyVersionIsZeroAndHasRandom8CharName()
}
}

[Theory]
[InlineData("454845b558934321ad350977dd095960")]
[InlineData("41e68894e3e54239abe61eb16cb0e158")]
[InlineData("a1bc683e730d425c9de5fdf00dbdc003")]
public void DoesNotHaveChangesWhenAssemblyVersionIsZeroAndHas32CharName(string name)
{
var ignoredName = CreateAssemblyName(new Version(0, 0, 0, 0), name: name);

var collector = new DependencyTelemetryCollector();
collector.AssemblyLoaded(ignoredName, "some-guid");

collector.HasChanges().Should().BeFalse($"{name} has a zero version");

var nonIgnoredName = CreateAssemblyName(new Version(1, 0, 0, 0), name: name);
collector.AssemblyLoaded(nonIgnoredName, "some-guid");
collector.HasChanges().Should().BeTrue($"{nonIgnoredName} has a non-zero version");
}

[Fact]
public void HasChangesWhenAddingSameAssemblyWithDifferentVersion()
{
Expand Down
Loading