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

Bearer scan --diff fails with broken pipe when line too long #1509

Closed
chasay opened this issue Feb 22, 2024 · 0 comments · Fixed by #1512
Closed

Bearer scan --diff fails with broken pipe when line too long #1509

chasay opened this issue Feb 22, 2024 · 0 comments · Fixed by #1512
Assignees
Labels
bug Something isn't working

Comments

@chasay
Copy link

chasay commented Feb 22, 2024

Description & Reproduction

When running Bearer with the --diff option and the scanner encounters an error it will return a Error: signal: broken pipe. This is because the error is not checked before returning from the parseDiff function.

Example command: go run ./cmd/bearer/main.go scan ~/code/repo-with-long-line-diff --diff

An example error would be a diff that contains a line longer than the MaxScanTokenSize. (64 * 1024 bytes). With this additional code, the returned error will be Error: bufio.Scanner: token too long.

Expected Behavior

The scan completes successfully.

Actual Behavior

> go run ./cmd/bearer/main.go scan ~/code/repo/ --diff
Analyzing codebase
⠹  (58264/-) [0s]
Loading rules
Scanning target ~/code/repo/
2024-02-21 16:45:28 ERR Git discovery failed process=main
Error: bufio.Scanner: token too long
exit status 1

Possible Fix

Proposed PR to address error

Instead of a bufio.Scanner use a Reader. Looks like you might have some utils that handle this already.

Your Environment

  • Operating System and version: Mac and Linux
  • Output of 'bearer version':
> go run ./cmd/bearer/main.go version
bearer version dev, build devSHA
> git log --oneline
0b4ecc08 (HEAD -> fix/return-parse-diff-scan-error, me/fix/return-parse-diff-scan-error) fix: return scan error if exists in parseDiff func
b3942b41 (origin/main, origin/HEAD, main) fix(golang): handle sprintf properly (#1503)
bearer version: 0.00.0
sha: xxx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants