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

Enable peekable-based binary sniffing on ZipArchiveArtifacts #2773

Merged
merged 6 commits into from
Feb 5, 2024

Conversation

scottoneil-ms
Copy link
Contributor

No description provided.

string extension = Path.GetExtension(Uri.ToString());
if (this.binaryExtensions.Contains(extension))
const int PeekWindowBytes = 1024;
var peekable = new PeekableStream(this.Stream, PeekWindowBytes);
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be disposed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, peekable just has the underlying stream and a managed buffer. 1k, in this case.

string extension = Path.GetExtension(Uri.ToString());
return this.binaryExtensions.Contains(extension);
GetArtifactData();
return this.bytes != null;
Copy link
Member

Choose a reason for hiding this comment

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

Before this check was cheap, now it looks like it's potentially much more expensive since you're introspecting the actual stream. Are there any concerns around perf changes here?

Copy link
Contributor Author

@scottoneil-ms scottoneil-ms Feb 1, 2024

Choose a reason for hiding this comment

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

Sort of, but that expectation has to be baked into the whole premise of categorizing based on contents.

I would say I just gained appreciation on another thread that the way we protect ourselves from scanning obviously bogus content is the file deny extensions, which remains a feature. So you could imagine that once you've passed that check, we're going to scan, so the only perf-sensitivity to this change would be when we do the first read. (Not if.) That's not a high-stakes question.

Interested in Michael's take on this.

Copy link
Member

@rwoll rwoll left a comment

Choose a reason for hiding this comment

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

Left minor question, otherwise LGTM.

Copy link
Member

@michaelcfanning michaelcfanning left a comment

Choose a reason for hiding this comment

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

:shipit:

@scottoneil-ms scottoneil-ms merged commit edbd822 into main Feb 5, 2024
8 checks passed
@scottoneil-ms scottoneil-ms deleted the users/scott/sniffZip branch February 5, 2024 23:51
rwoll added a commit that referenced this pull request Feb 8, 2024
rwoll added a commit that referenced this pull request Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants