fix: panic in linear myers algorithm#44
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug in the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request addresses a panic in the Myers diff algorithm's suffix-scanning loop by adding a necessary bounds check. While the fix for the suffix loop is correct, I've identified an identical vulnerability in the prefix-scanning loop just a few lines above the change. This related bug can also cause a panic. I've left a critical review comment on the changed line, detailing the issue and providing a code snippet to fix the vulnerable prefix loop.
In `linearSpaceMyersRecWithIndices`, the suffix-scanning loop:
```go
for suffix < n-prefix && a[aEnd-1-suffix] == b[bEnd-1-suffix] {
```
bounds the scan against n-prefix (a's remaining length after prefix) but not against m-prefix (b's remaining length).
With the fuzzer's input a="\n\n\n\n\n\n\n\n\n0" → 10 lines, b="0" → 1 line:
n=10, m=1, prefix=0
suffix=0: a[9]="0" == b[0]="0" → true, suffix becomes 1
suffix=1: tries b[1-1-1] = b[-1] → index out of range panic
Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
|
I ended up fixing more panics, all found via fuzz testing with algorithm locked to linear Myers. |
The fix PR neticdk/go-stdlib#44 Replace the library for now. Add fuzzing test, keep panic causing vectors. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
The fix PR neticdk/go-stdlib#44 Replace the library for now. Add fuzzing test, keep panic causing vectors. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
The fix PR neticdk/go-stdlib#44 Replace the library for now. Add fuzzing test, keep panic causing vectors. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
Same as siderolabs/talos#12992. The fix PR: neticdk/go-stdlib#44. Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
Same as siderolabs/talos#12992. The fix PR: neticdk/go-stdlib#44. Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com> (cherry picked from commit 621d3f4)
|
@smira Thanks for the PR. Nice find! I wrote two tests that confirm the clamping and suffix limit panics: I'll add the tests after merging the PR. |
|
@smira just wanted to give you a heads up that i pushed v1.0.1 edited: tagged v0.2.2 but realized we had published and retracted v1.0.0 some time ago and go really wants to use the newest version even though it's retracted |
In
linearSpaceMyersRecWithIndices, the suffix-scanning loop:bounds the scan against n-prefix (a's remaining length after prefix) but not against m-prefix (b's remaining length).
With the fuzzer's input a="\n\n\n\n\n\n\n\n\n0" → 10 lines, b="0" → 1 line: