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 reading syft json from stdin by redirect #1299

Merged
merged 1 commit into from
May 16, 2023

Conversation

devfbe
Copy link
Contributor

@devfbe devfbe commented May 15, 2023

I figured out that running cat syft.json | grype works but grype < syft.json does not work. This happens, because the IsPipedInput method only checks if stdin is a pipe which will be false if stdin is fed by a redirect.

The go idiomatic way to fix this is by just checking if the file produced by stat has a size > 0.

Implemented this check, that will recognize stdin by redirect, in the IsPipedInput() method. Renamed the method to IsStdinPipeOrRedirect().

I figured out that running `cat syft.json | grype` works but
`grype < syft.json` does not work. This happens, because the
IsPipedInput method only checks if stdin is a pipe which will be false
if stdin is fed by a redirect.

The go idiomatic way to fix this is by just checking if the file
produced by stat has a size > 0.

Implemented this check, that will recognize stdin by redirect, in the
IsPipedInput() method. Renamed the method to IsStdinPipeOrRedirect().

Co-Authored-By: Benjamin Neff <benjamin@coding4coffee.ch>
Signed-off-by: Felix Becker <git@felixbecker.name>
Copy link
Contributor

@wagoodman wagoodman left a comment

Choose a reason for hiding this comment

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

nice improvement! We used to only use the size as an indication of piping, which is wrong (plenty of race conditions there). But I see the difference with the use case you highlighted 👍

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.

2 participants