Skip to content

Commit

Permalink
fixes dlclark#32 make sure octal parsing only eats chars 0-7
Browse files Browse the repository at this point in the history
  • Loading branch information
dlclark committed Oct 7, 2020
1 parent bbc9f75 commit 955551b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,3 +1092,40 @@ func TestEmptyCaptureLargeRepeat(t *testing.T) {
t.Fatal("Expected 2 matches, got more")
}
}

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

var testCases = []struct {
r, s []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},
},
}

for _, c := range testCases {
r := string(c.r)
t.Run(r, func(t *testing.T) {
_, err := Compile(r, Multiline|ECMAScript|Debug)
// should fail compiling
if err == nil {
t.Fatal("should fail compile, but didn't")
}
})
}

}
2 changes: 1 addition & 1 deletion syntax/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ func (p *parser) scanOctal() rune {
//we know the first char is good because the caller had to check
i := 0
d := int(p.rightChar(0) - '0')
for c > 0 && d <= 7 {
for c > 0 && d <= 7 && d >= 0 {
if i >= 0x20 && p.useOptionE() {
break
}
Expand Down

0 comments on commit 955551b

Please sign in to comment.