Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable lineLimitReader when handle BDAT data #139

Merged
merged 7 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Conn struct {
locker sync.Mutex
binarymime bool

bdatReader *lineLimitReader
bdatPipe *io.PipeWriter
bdatStatus *statusCollector // used for BDAT on LMTP
dataResult chan error
Expand All @@ -60,15 +61,17 @@ func newConn(c net.Conn, s *Server) *Conn {
}

func (c *Conn) init() {
c.bdatReader = &lineLimitReader{
emersion marked this conversation as resolved.
Show resolved Hide resolved
R: c.conn,
LineLimit: c.server.MaxLineLength,
DisableCheck: false,
}
rwc := struct {
io.Reader
io.Writer
io.Closer
}{
Reader: &lineLimitReader{
R: c.conn,
LineLimit: c.server.MaxLineLength,
},
Reader: c.bdatReader,
Writer: c.conn,
Closer: c.conn,
}
Expand Down Expand Up @@ -739,6 +742,7 @@ func (c *Conn) handleBdat(arg string) {
}()
}

c.bdatReader.DisableCheck = true
emersion marked this conversation as resolved.
Show resolved Hide resolved
chunk := io.LimitReader(c.text.R, int64(size))
_, err = io.Copy(c.bdatPipe, chunk)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions lengthlimit_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ var ErrTooLongLine = errors.New("smtp: too longer line in input stream")
//
// If line length exceeds the limit - Read returns ErrTooLongLine
type lineLimitReader struct {
R io.Reader
LineLimit int
R io.Reader
LineLimit int
DisableCheck bool

curLineLength int
}

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

Expand All @@ -28,7 +29,7 @@ func (r *lineLimitReader) Read(b []byte) (int, error) {
return n, err
}

if r.LineLimit == 0 {
if r.LineLimit == 0 || r.DisableCheck {
return n, nil
}

Expand Down