Skip to content

Commit

Permalink
Disable lineLimitReader when handle BDAT data
Browse files Browse the repository at this point in the history
References: #81 (comment)
  • Loading branch information
norguhtar authored Mar 24, 2021
1 parent ca8725c commit f92bf7f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ type Conn struct {
locker sync.Mutex
binarymime bool

bdatPipe *io.PipeWriter
bdatStatus *statusCollector // used for BDAT on LMTP
dataResult chan error
bytesReceived int // counts total size of chunks when BDAT is used
lineLimitReader *lineLimitReader
bdatPipe *io.PipeWriter
bdatStatus *statusCollector // used for BDAT on LMTP
dataResult chan error
bytesReceived int // counts total size of chunks when BDAT is used

fromReceived bool
recipients []string
Expand All @@ -60,15 +61,16 @@ func newConn(c net.Conn, s *Server) *Conn {
}

func (c *Conn) init() {
c.lineLimitReader = &lineLimitReader{
R: c.conn,
LineLimit: c.server.MaxLineLength,
}
rwc := struct {
io.Reader
io.Writer
io.Closer
}{
Reader: &lineLimitReader{
R: c.conn,
LineLimit: c.server.MaxLineLength,
},
Reader: c.lineLimitReader,
Writer: c.conn,
Closer: c.conn,
}
Expand Down Expand Up @@ -741,6 +743,8 @@ func (c *Conn) handleBdat(arg string) {
}()
}

c.lineLimitReader.LineLimit = 0

chunk := io.LimitReader(c.text.R, int64(size))
_, err = io.Copy(c.bdatPipe, chunk)
if err != nil {
Expand All @@ -755,12 +759,15 @@ func (c *Conn) handleBdat(arg string) {
}

c.reset()
c.lineLimitReader.LineLimit = c.server.MaxLineLength
return
}

c.bytesReceived += int(size)

if last {
c.lineLimitReader.LineLimit = c.server.MaxLineLength

c.bdatPipe.Close()

err := <-c.dataResult
Expand Down
2 changes: 1 addition & 1 deletion lengthlimit_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type lineLimitReader struct {
}

func (r *lineLimitReader) Read(b []byte) (int, error) {
if r.curLineLength > r.LineLimit {
if r.curLineLength > r.LineLimit && r.LineLimit > 0 {
return 0, ErrTooLongLine
}

Expand Down

0 comments on commit f92bf7f

Please sign in to comment.