Skip to content

Commit 955551b

Browse files
committed
fixes #32 make sure octal parsing only eats chars 0-7
1 parent bbc9f75 commit 955551b

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

regexp_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,3 +1092,40 @@ func TestEmptyCaptureLargeRepeat(t *testing.T) {
10921092
t.Fatal("Expected 2 matches, got more")
10931093
}
10941094
}
1095+
1096+
func TestFuzzBytes(t *testing.T) {
1097+
//some crash cases found from fuzzing
1098+
1099+
var testCases = []struct {
1100+
r, s []byte
1101+
}{
1102+
{
1103+
r: []byte{0x28, 0x28, 0x29, 0x5c, 0x37, 0x28, 0x3f, 0x28, 0x29, 0x29},
1104+
s: []byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
1105+
},
1106+
{
1107+
r: []byte{0x28, 0x5c, 0x32, 0x28, 0x3f, 0x28, 0x30, 0x29, 0x29},
1108+
s: []byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
1109+
},
1110+
{
1111+
r: []byte{0x28, 0x3f, 0x28, 0x29, 0x29, 0x5c, 0x31, 0x30, 0x28, 0x3f, 0x28, 0x30, 0x29},
1112+
s: []byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
1113+
},
1114+
{
1115+
r: []byte{0x28, 0x29, 0x28, 0x28, 0x29, 0x5c, 0x37, 0x28, 0x3f, 0x28, 0x29, 0x29},
1116+
s: []byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
1117+
},
1118+
}
1119+
1120+
for _, c := range testCases {
1121+
r := string(c.r)
1122+
t.Run(r, func(t *testing.T) {
1123+
_, err := Compile(r, Multiline|ECMAScript|Debug)
1124+
// should fail compiling
1125+
if err == nil {
1126+
t.Fatal("should fail compile, but didn't")
1127+
}
1128+
})
1129+
}
1130+
1131+
}

syntax/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ func (p *parser) scanOctal() rune {
18181818
//we know the first char is good because the caller had to check
18191819
i := 0
18201820
d := int(p.rightChar(0) - '0')
1821-
for c > 0 && d <= 7 {
1821+
for c > 0 && d <= 7 && d >= 0 {
18221822
if i >= 0x20 && p.useOptionE() {
18231823
break
18241824
}

0 commit comments

Comments
 (0)