aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-01-05 12:29:46 +0100
committerDmitry Vyukov <dvyukov@google.com>2017-01-09 20:19:44 +0100
commit0913359f7945a0cc1bca95ce842e2db93296e712 (patch)
treedcf5ae8a007b035d785cb37a9d9b90141845cb9d
parent26f0782d08cd55979593f50c37aea5daee059a3b (diff)
prog: increase line length limit when deserializing programs
bufio.Scanner has a default limit of 4K per line, if a program contains longer line, it fails. Extend the limit to 64K. Also check scanning errors. Turns out even scanning of bytes.Buffer can fail due to the line limit.
-rw-r--r--prog/encoding.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/prog/encoding.go b/prog/encoding.go
index 11c86fb44..757c32b8c 100644
--- a/prog/encoding.go
+++ b/prog/encoding.go
@@ -120,6 +120,7 @@ func (a *Arg) serialize(buf io.Writer, vars map[*Arg]int, varSeq *int) {
func Deserialize(data []byte) (prog *Prog, err error) {
prog = new(Prog)
p := &parser{r: bufio.NewScanner(bytes.NewReader(data))}
+ p.r.Buffer(nil, maxLineLen)
vars := make(map[string]*Arg)
for p.Scan() {
if p.EOF() || p.Char() == '#' {
@@ -171,7 +172,7 @@ func Deserialize(data []byte) (prog *Prog, err error) {
vars[r] = c.Ret
}
}
- if p.Err() != nil {
+ if err := p.Err(); err != nil {
return nil, err
}
if err := prog.validate(); err != nil {
@@ -351,6 +352,7 @@ func parseArg(typ sys.Type, p *parser, vars map[string]*Arg) (*Arg, error) {
const (
encodingAddrBase = 0x7f0000000000
encodingPageSize = 4 << 10
+ maxLineLen = 64 << 10
)
func serializeAddr(a *Arg, base bool) string {
@@ -522,6 +524,7 @@ func (p *parser) failf(msg string, args ...interface{}) {
func CallSet(data []byte) (map[string]struct{}, error) {
calls := make(map[string]struct{})
s := bufio.NewScanner(bytes.NewReader(data))
+ s.Buffer(nil, maxLineLen)
for s.Scan() {
ln := s.Bytes()
if len(ln) == 0 || ln[0] == '#' {
@@ -544,6 +547,9 @@ func CallSet(data []byte) (map[string]struct{}, error) {
}
calls[string(call)] = struct{}{}
}
+ if err := s.Err(); err != nil {
+ return nil, err
+ }
if len(calls) == 0 {
return nil, fmt.Errorf("program does not contain any calls")
}