Skip to content

Commit d31144b

Browse files
strajansebastiansmira
authored andcommitted
Buffer increase (#738)
Increase Scanner buffer size for Stanza reader
1 parent c7a3a10 commit d31144b

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ List of contributors, in chronological order:
3232
* Ludovico Cavedon (https://github.com/cavedon)
3333
* Petr Jediny (https://github.com/pjediny)
3434
* Maximilian Stein (https://github.com/steinymity)
35+
* Strajan Sebastian (https://github.com/strajansebastian)

deb/format.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import (
1111
// Stanza or paragraph of Debian control file
1212
type Stanza map[string]string
1313

14+
// MaxFieldSize is maximum stanza field size in bytes
15+
const MaxFieldSize = 2 * 1024 * 1024
16+
1417
// Canonical order of fields in stanza
1518
// Taken from: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/vivid/apt/vivid/view/head:/apt-pkg/tagfile.cc#L504
1619
var (
@@ -214,7 +217,10 @@ type ControlFileReader struct {
214217

215218
// NewControlFileReader creates ControlFileReader, it wraps with buffering
216219
func NewControlFileReader(r io.Reader) *ControlFileReader {
217-
return &ControlFileReader{scanner: bufio.NewScanner(bufio.NewReaderSize(r, 32768))}
220+
scnr := bufio.NewScanner(bufio.NewReaderSize(r, 32768))
221+
scnr.Buffer(nil, MaxFieldSize)
222+
223+
return &ControlFileReader{scanner: scnr}
218224
}
219225

220226
// ReadStanza reeads one stanza from control file

deb/format_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package deb
33
import (
44
"bufio"
55
"bytes"
6+
"os"
67
"strings"
78

89
. "gopkg.in/check.v1"
@@ -135,6 +136,17 @@ func (s *ControlFileSuite) TestCanonicalCase(c *C) {
135136
c.Check(canonicalCase("packaGe-lIst"), Equals, "Package-List")
136137
}
137138

139+
func (s *ControlFileSuite) TestLongFields(c *C) {
140+
f, err := os.Open("long.stanza")
141+
c.Assert(err, IsNil)
142+
defer f.Close()
143+
144+
r := NewControlFileReader(f)
145+
stanza, e := r.ReadStanza(false)
146+
c.Assert(e, IsNil)
147+
c.Assert(len(stanza["Provides"]), Equals, 586929)
148+
}
149+
138150
func (s *ControlFileSuite) BenchmarkReadStanza(c *C) {
139151
for i := 0; i < c.N; i++ {
140152
reader := bytes.NewBufferString(controlFile)

deb/long.stanza

Lines changed: 12 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)