Skip to content

Commit

Permalink
Merge pull request #18 from kgoins/bug/token-too-long
Browse files Browse the repository at this point in the history
added const for ldap max token size and plumbed into line scanners
  • Loading branch information
kgoins authored Mar 23, 2021
2 parents 0fd4292 + 56320dd commit 53781e1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ testdata/
ldsview
.vscode/
release/
bin/
4 changes: 3 additions & 1 deletion pkg/ldif_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/kgoins/ldsview/internal"
)

const LDAPMaxLineSize int = 1024 * 1024 * 10

// LdifParser implements EntityBuilder and constructs LDAP Entities
// from an ldif file.
type LdifParser struct {
Expand All @@ -32,7 +34,7 @@ func NewLdifParser(filename string) LdifParser {
entityFilter: []IEntityFilter{},
attributeFilter: internal.NewHashSetStr(),
titleLineRegex: regex,
scannerBufferSize: 1024 * 1024 * 10,
scannerBufferSize: LDAPMaxLineSize,
}
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/positioned_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func NewPositionedScanner(inputStream io.Reader) *PositionedScanner {
scanner: bufio.NewScanner(inputStream),
}

lineBuf := make([]byte, LDAPMaxLineSize)
positionedScanner.Buffer(lineBuf, LDAPMaxLineSize)

scanLines := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
advance, token, err = bufio.ScanLines(data, atEOF)
positionedScanner.pos += int64(advance)
Expand Down

0 comments on commit 53781e1

Please sign in to comment.