Skip to content

Commit

Permalink
fixes dlclark#36 fix bug in BM-prefix check when handling runes more …
Browse files Browse the repository at this point in the history
…than 16 bits.
  • Loading branch information
dlclark committed Oct 13, 2020
1 parent f49f484 commit 346446b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
37 changes: 31 additions & 6 deletions regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,27 +1093,23 @@ func TestEmptyCaptureLargeRepeat(t *testing.T) {
}
}

func TestFuzzBytes(t *testing.T) {
func TestFuzzBytes_NoCompile(t *testing.T) {
//some crash cases found from fuzzing

var testCases = []struct {
r, s []byte
r []byte
}{
{
r: []byte{0x28, 0x28, 0x29, 0x5c, 0x37, 0x28, 0x3f, 0x28, 0x29, 0x29},
s: []byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
},
{
r: []byte{0x28, 0x5c, 0x32, 0x28, 0x3f, 0x28, 0x30, 0x29, 0x29},
s: []byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
},
{
r: []byte{0x28, 0x3f, 0x28, 0x29, 0x29, 0x5c, 0x31, 0x30, 0x28, 0x3f, 0x28, 0x30, 0x29},
s: []byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
},
{
r: []byte{0x28, 0x29, 0x28, 0x28, 0x29, 0x5c, 0x37, 0x28, 0x3f, 0x28, 0x29, 0x29},
s: []byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
},
}

Expand All @@ -1129,3 +1125,32 @@ func TestFuzzBytes(t *testing.T) {
}

}

func TestFuzzBytes_Match(t *testing.T) {

var testCases = []struct {
r, s []byte
}{
{
r: []byte{0x30, 0xbf, 0x30, 0x2a, 0x30, 0x30},
s: []byte{0xf0, 0xb0, 0x80, 0x91, 0xf7},
},
{
r: []byte{0x30, 0xaf, 0xf3, 0x30, 0x2a},
s: []byte{0xf3, 0x80, 0x80, 0x87, 0x80, 0x89},
},
}

for _, c := range testCases {
r := string(c.r)
t.Run(r, func(t *testing.T) {
re, err := Compile(r, 0)

if err != nil {
t.Fatal("should compile, but didn't")
}

re.MatchString(string(c.s))
})
}
}
2 changes: 1 addition & 1 deletion syntax/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ func (b *BmPrefix) Scan(text []rune, index, beglimit, endlimit int) int {

if chTest != b.pattern[match] {
advance = b.positive[match]
if (chTest & 0xFF80) == 0 {
if chTest < 128 {
test2 = (match - startmatch) + b.negativeASCII[chTest]
} else if chTest < 0xffff && len(b.negativeUnicode) > 0 {
unicodeLookup = b.negativeUnicode[chTest>>8]
Expand Down

0 comments on commit 346446b

Please sign in to comment.