File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ import (
1111// Stanza or paragraph of Debian control file
1212type 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
1619var (
@@ -214,7 +217,10 @@ type ControlFileReader struct {
214217
215218// NewControlFileReader creates ControlFileReader, it wraps with buffering
216219func 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
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package deb
33import (
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+
138150func (s * ControlFileSuite ) BenchmarkReadStanza (c * C ) {
139151 for i := 0 ; i < c .N ; i ++ {
140152 reader := bytes .NewBufferString (controlFile )
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments