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

Project status; Panic in parsec.String() with unterminated string #45

Open
rm-hull opened this issue Aug 21, 2022 · 1 comment
Open

Comments

@rm-hull
Copy link

rm-hull commented Aug 21, 2022

Hi @prataprc, first off: is this project still maintained? Im guessing that the Travis CI is no longer working and that the version of go (1.13) means that it wont build with modern toolchain?

If I run an unterminated string through the String() parser, it panics with runtime error: index out of range [6] with length 6:

data := []byte(`"hello`)
scanner := parsec.NewScanner(data)
node, _ := parsec.String()(scanner)
print(node)

I think the issue is in tokenizer.go, in method scanString (suggested changes in comments):

func scanString(txt []byte) (tok []byte, readn int) {
	if len(txt) < 2 {
		return nil, 0
	}

	e := 1
	for txt[e] != '"' {
		c := txt[e]
		if c == '\\' || c == '"' || c < ' ' {
			break
		}
		if c < utf8.RuneSelf {
			e++
			// SUGGESTED CHANGE 1
			// if e >= len(txt) {
			// 	return nil, 0
			// }
			continue
		}
		r, size := utf8.DecodeRune(txt[e:])
		if r == utf8.RuneError && size == 1 {
			return nil, 0
		}
		e += size

		// SUGGESTED CHANGE 2
		// if e >= len(txt) {
		// 	return nil, 0
		// }
	}

	// ...

Is there an appetite for bringing this project up-to-date and fixing this issue?

@rm-hull
Copy link
Author

rm-hull commented Aug 21, 2022

Hmm, diving in a bit further, I see there is a test case:

	// malformed string
	func() {
		defer func() {
			if r := recover(); r == nil {
				t.Errorf("expected panic")
			}
		}()
		s = NewScanner([]byte(`"hello`))
		String()(s)
	}()

Could you give some background as to why you would expect that to panic

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

1 participant