sergi / go-diff

Diff, match and patch text in Go
MIT License
1.81k stars 207 forks source link

panic: runtime error: slice bounds out of range #127

Open iambus opened 2 years ago

iambus commented 2 years ago
func TestPatchMakeOutOfRangePanic(t *testing.T) {
    text1 := `
  1111111111111 000000
  ------------- ------
  xxxxxxxxxxxxx ------
  xxxxxxxxxxxxx ------
  xxxxxxxxxxxxx xxxxxx
  xxxxxxxxxxxxx ......
  xxxxxxxxxxxxx 111111
  xxxxxxxxxxxxx ??????
  xxxxxxxxxxxxx 333333
  xxxxxxxxxxxxx 555555
  xxxxxxxxxx xxxxx
  xxxxxxxxxx xxxxx
  xxxxxxxxxx xxxxx
  xxxxxxxxxx xxxxx
`
    text2 := `
  2222222222222 000000
  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
    dmp := New()
    patches := dmp.PatchMake(text1, text2)
    assert.Equal(t, 6, len(patches), "aa")
}`
=== RUN   TestPatchMakeOutOfRangePanic
--- FAIL: TestPatchMakeOutOfRangePanic (0.00s)

panic: runtime error: slice bounds out of range [103:100] [recovered]
    panic: runtime error: slice bounds out of range [103:100]

goroutine 19 [running]:
testing.tRunner.func1.2({0x1d6020, 0xc0000a2738})
    /usr/go1.17/src/testing/testing.go:1209 +0x24e
testing.tRunner.func1()
    /usr/go1.17/src/testing/testing.go:1212 +0x218
panic({0x1d6020, 0xc0000a2738})
    /usr/go1.17/src/runtime/panic.go:1038 +0x215
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).patchMake2(0xc000093ed0, {0x1f6c06, 0x0}, {0xc00011c500, 0x8, 0x10})

    /go-diff/diffmatchpatch/patch.go:171 +0xa69
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).PatchMake(0xc000093ed0, {0xc000093e38, 0xb, 0x1a})
    /diffmatchpatch/patch.go:131 +0x1bc
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).PatchMake(0xe6393, {0xc000049f40, 0x24e39b, 0xf})
    /go-diff/diffmatchpatch/patch.go:129 +0x33b
github.com/sergi/go-diff/diffmatchpatch.TestPatchMakeOutOfRangePanic(0x0)
    /go-diff/diffmatchpatch/patch_test.go:362 +0x12a
testing.tRunner(0xc000085ba0, 0x1fc6b0)
    /usr/go1.17/src/testing/testing.go:1259 +0x102
created by testing.(*T).Run
    /usr/go1.17/src/testing/testing.go:1306 +0x35a

Process finished with the exit code 1
vbonthaCW commented 1 year ago

Any latest developments on this issue?

pwnetrationguru commented 6 months ago

Yah, I'm getting a similar error in this function: https://github.com/sergi/go-diff/blob/5b0b94c5c0d3d261e044521f7f46479ef869cf76/diffmatchpatch/diff.go#L404

User
panic: runtime error: index out of range [65533] with length 65192

goroutine 1 [running]:
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).DiffCharsToLines(0x1400be1c2c8?, {0x1400b52c800, 0x27, 0x22000?}, {0x140126d6000, 0xfea8, 0x22000?})
        /Users/omerta/go/pkg/mod/github.com/sergi/go-diff@v1.1.0/diffmatchpatch/diff.go:452 +0x240
github.com/go-git/go-git/v5/utils/diff.DoWithTimeout({0x14024ede000?, 0x100c4b840?}, {0x14025490000?, 0x1009cebcc?}, 0x14006abbbd0?)
        /Users/omerta/go/pkg/mod/github.com/go-git/go-git/v5@v5.11.0/utils/diff/diff.go:37 +0xe4
github.com/go-git/go-git/v5/utils/diff.Do(...)
        /Users/omerta/go/pkg/mod/github.com/go-git/go-git/v5@v5.11.0/utils/diff/diff.go:22
github.com/go-git/go-git/v5/plumbing/object.filePatchWithContext({0x100f9d9c0, 0x1012a37c0}, 0x14000199f00)
        /Users/omerta/go/pkg/mod/github.com/go-git/go-git/v5@v5.11.0/plumbing/object/patch.go:68 +0x140
github.com/go-git/go-git/v5/plumbing/object.getPatchContext({0x100f9d9c0, 0x1012a37c0}, {0x0, 0x0}, {0x14000125e18, 0x3, 0x100f9f460?})
        /Users/omerta/go/pkg/mod/github.com/go-git/go-git/v5@v5.11.0/plumbing/object/patch.go:38 +0xc4
github.com/go-git/go-git/v5/plumbing/object.Changes.PatchContext(...)
        /Users/omerta/go/pkg/mod/github.com/go-git/go-git/v5@v5.11.0/plumbing/object/change.go:158
github.com/go-git/go-git/v5/plumbing/object.(*Tree).PatchContext(0x34bdbbd1b9a656cc?, {0x100f9d9c0, 0x1012a37c0}, 0x101766d18?)
        /Users/omerta/go/pkg/mod/github.com/go-git/go-git/v5@v5.11.0/plumbing/object/tree.go:339 +0x7c
github.com/go-git/go-git/v5/plumbing/object.(*Commit).StatsContext(0x14000000900, {0x100f9d9c0, 0x1012a37c0})
        /Users/omerta/go/pkg/mod/github.com/go-git/go-git/v5@v5.11.0/plumbing/object/commit.go:393 +0x1a0
github.com/go-git/go-git/v5/plumbing/object.(*Commit).Stats(...)
        /Users/omerta/go/pkg/mod/github.com/go-git/go-git/v5@v5.11.0/plumbing/object/commit.go:369
github.com/devzero-inc/dora/backend/processing.ParseGitRepo.func1(0x14000000900)
        /Users/omerta/playground/code/dora/backend/processing/github.go:220 +0x328
github.com/go-git/go-git/v5/plumbing/object.(*commitPreIterator).ForEach(0x140002a2d80?, 0x14000c4a330)
        /Users/omerta/go/pkg/mod/github.com/go-git/go-git/v5@v5.11.0/plumbing/object/commit_walker.go:105 +0x80
github.com/devzero-inc/dora/backend/processing.ParseGitRepo({0x14017fbe140?, 0x1400011a020?}, 0x14000a106e0, 0x4daf)
        /Users/omerta/playground/code/dora/backend/processing/github.go:186 +0x240
github.com/devzero-inc/dora/backend/processing.ProcessGithubRepo({0x100f9d9c0?, 0x1012a37c0?}, {0x100da430a, 0xa}, {0x100da2bb7, 0x6}, {0x100da303f, 0x7}, {0x100db654f, 0x28}, ...)
        /Users/omerta/playground/code/dora/backend/processing/github.go:271 +0x4e4
main.main()
        /Users/omerta/playground/code/dora/backend/scripts/generate_dora_db.go:200 +0xd78

Seems oddly close to a max int16, but that doesn't really make sense with Golang AFAICT (always 32 or 64bit).

I see last commit to repo was 8 months ago -- is this still actively being maintained?