fix: prevent index out-of-range panic in hasCommonSubstring#38
Open
edznux-dd wants to merge 1 commit intoglaslos:mainfrom
Open
fix: prevent index out-of-range panic in hasCommonSubstring#38edznux-dd wants to merge 1 commit intoglaslos:mainfrom
edznux-dd wants to merge 1 commit intoglaslos:mainfrom
Conversation
Owner
|
@edznux-dd can you rebase? I updated main to go1.18 to support testing.F |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
👋, I was looking a some of my app and discovered a small bugs in the library.
So here's a fix and some description of the issue!
I took the liberty to add a fuzz test as I don't think you have any fuzz test in here yet. I've run it for a bit after the fix and didn't seem to find any other bugs :)
Description
Distanceparses hash strings by splitting on:but imposes no length cap on the body segments.hasCommonSubstringallocates ahashesslice of fixed sizespamSumLength - (rollingWindow - 1)= 64 - 6 = 58, then writes into it at indexi-(rollingWindow-1)while loopingfor i = rollingWindow-1; i < s1Len; i++. When the hash body is 65 or more characters long the index reaches 58, which is out of bounds, and the runtime raises a fatal panic.Crash Input
I've added a regression test for this case, but for convenience:
Root Cause
In
score.go:104: