8000 Fix currentLine out of bounds error by bplaxco · Pull Request #1810 · gitleaks/gitleaks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix currentLine out of bounds error #1810

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 8000 statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025

Conversation

bplaxco
Copy link
Contributor
@bplaxco bplaxco commented Apr 2, 2025

Description:

segment.adjustMatchIndex(matchIndex) was above segment.lineEndIndex(currentRaw, matchIndex[1]-matchIndex[0]) there were cases where it would cause an out of bounds error.

This change resolves the issue by just assuming the whole segment is a opaque chunk of text and starts at the boundaries of the segment instead so that the order doesn't matter as much.

The other option would have been to reorder the assignments and add tests to account for that case, but I figured this option is less likely to have gotchas when working with different encoding formats at the potential expense of getting an extra line or two if an encoding format in the future ever allows multiple lines of encoded content to be considered a single segment.

Explain the purpose of the PR.

Checklist:

  • Does your PR pass tests?
  • Have you written new tests for your changes? (N/A: covered by existing tests)
  • Have you lint your code locally prior to submission?

@bplaxco
Copy link
Contributor Author
bplaxco commented Apr 2, 2025

@zricethezav, @thewizzy noticed this issue in our CI run that included some decoding tests:

https://github.com/leaktk/scanner/actions/runs/14210109004/job/39815606323

It thought the matchlen was 128 when len(currentRaw) was only 95.

I think this should fix the issue and be a little more robust with future decoding cases. @thewizzy, can you point the failing branch at the fork and confirm the fix as well? I tested it locally when making the change and it resolved it.

Because `segment.adjustMatchIndex(matchIndex)` was above
`segment.lineEndIndex(currentRaw, matchIndex[1]-matchIndex[0])` there
were cases where it would cause an out of bounds error.

This change resolves the issue by just assuming the whole segment is a
opaque chunk of text and starts at the boundaries of the segment instead
so that the order doesn't matter as much.

The other option would have been to reorder the assignments and add
tests to account for that case, but I figured this option is less likely
to have gotchas when working with different encoding formats at the
potential expense of getting an extra line or two if an encoding format
in the future ever allows multiple lines of encoded content to be
considered a single segment.
@bplaxco bplaxco force-pushed the fix-current-line-bug branch from cc42ba7 to e4cae2f Compare April 2, 2025 20:50
@thewizzy
Copy link
thewizzy commented Apr 2, 2025

@zricethezav, @thewizzy noticed this issue in our CI run that included some decoding tests:

https://github.com/leaktk/scanner/actions/runs/14210109004/job/39815606323

It thought the matchlen was 128 when len(currentRaw) was only 95.

I think this should fix the issue and be a little more robust with future decoding cases. @thewizzy, can you point the failing branch at the fork and confirm the fix as well? I tested it locally when making the change and it resolved it.

I pointed it to the fix and it resolved the issue in our tests.

leaktk/scanner#107

@zricethezav
Copy link
Collaborator

LGTM, thanks guys 👍🏻

@zricethezav zricethezav merged commit 4b54104 into gitleaks:master Apr 3, 2025
2 checks passed
@bplaxco bplaxco deleted the fix-current-line- 7BB5 bug branch April 15, 2025 22:57
sirakav pushed a commit to sirakav/gitleaks that referenced this pull request Apr 25, 2025
Because `segment.adjustMatchIndex(matchIndex)` was above
`segment.lineEndIndex(currentRaw, matchIndex[1]-matchIndex[0])` there
were cases where it would cause an out of bounds error.

This change resolves the issue by just assuming the whole segment is a
opaque chunk of text and starts at the boundaries of the segment instead
so that the order doesn't matter as much.

The other option would have been to reorder the assignments and add
tests to account for that case, but I figured this option is less likely
to have gotchas when working with different encoding formats at the
potential expense of getting an extra line or two if an encoding format
in the future ever allows multiple lines of encoded content to be
considered a single segment.
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
0