IBM / license-scanner

License Scanner
Apache License 2.0
6 stars 3 forks source link

bug: panic with index out of range when characters increase in size by ToLower() #26

Closed markstur closed 1 year ago

markstur commented 1 year ago

In two different locations of normalizer:replaceMatchesWithStringsAndUpdateIndexMap() (line numbers vary by version) an index out of range error will happen when the NormalizedText increases in length after the IndexMap is created (and the IndexMap isn't adjusted. An example of the error output is below.

This is happening when we encounter special characters that increase in length on ToLower().


panic: runtime error: index out of range [2075] with length 2072

goroutine 592509 [running]: github.com/IBM/license-scanner/normalizer.(NormalizationData).replaceMatchesWithStringsAndUpdateIndexMap(0xc000f39750, {0xc001ae2000?, 0xfb, 0x81c?}, {0xc001ae1000, 0xfb, 0x0?}) /Users/markstur/go/src/github.com/ibm/license-scanner/normalizer/normalizer.go:559 +0x725 github.com/IBM/license-scanner/normalizer.(NormalizationData).replaceMatchesWithStringAndUpdateIndexMap(0xc000f39750, {0xc001ae2000?, 0xfb, 0x155}, {0x141da08, 0x1}) /Users/markstur/go/src/github.com/ibm/license-scanner/normalizer/normalizer.go:513 +0x226 github.com/IBM/license-scanner/normalizer.(NormalizationData).regexpReplacePatternAndUpdateIndexMap(0xc000f39750, 0xa22?, {0x141da08, 0x1}) /Users/markstur/go/src/github.com/ibm/license-scanner/normalizer/normalizer.go:291 +0xe8 github.com/IBM/license-scanner/normalizer.(NormalizationData).replaceWhitespace(0xc000f39750?) /Users/markstur/go/src/github.com/ibm/license-scanner/normalizer/normalizer.go:481 +0x31