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

Runtime error: index out of range #225

Open
4k7 opened this issue Feb 15, 2021 · 2 comments
Open

Runtime error: index out of range #225

4k7 opened this issue Feb 15, 2021 · 2 comments

Comments

@4k7
Copy link

4k7 commented Feb 15, 2021

Hi,

In some cases , the "pos" value in RFC5322 class (mail/rfc5321/address.go) becomes -2, that leads to an runtime error (index out of range) in the functions peek() & next() in Parser class (mail/rfc5321/parse.go).

It happens here, if pos = -1.

s.pos = pos - 1 //- 1 // rewind to the saved position

This is line from this function (mail/rfc5321/address.go).

// mailbox  =   name-addr / addr-spec
func (s *RFC5322) mailbox() error {
	pos := s.pos // save the position
	if err := s.nameAddr(); err != nil {
		if err == errExpectingAngleAddress && s.ch != ':' { // ':' means it's a group
			// we'll attempt to parse as an email address without angle brackets
			s.addr.DisplayName = ""
			s.addr.DisplayNameQuoted = false
			s.pos = pos - 1 //- 1 // rewind to the saved position
			if s.pos > -1 {
				s.ch = s.buf[s.pos]
			}
			if err = s.Parser.mailbox(); err != nil {
				return err
			}
			s.addAddress()
		} else {
			return err
		}
	}
	return nil
}

Thanks!

@flashmob
Copy link
Owner

flashmob commented Feb 16, 2021 via email

@4k7
Copy link
Author

4k7 commented Feb 16, 2021

There are no sample input, but after this fix, the error no longer appears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants