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

Parsing very long literal sequences is broken in several ways #1104

Closed
fingolfin opened this issue Jan 25, 2017 · 3 comments · Fixed by #2467
Closed

Parsing very long literal sequences is broken in several ways #1104

fingolfin opened this issue Jan 25, 2017 · 3 comments · Fixed by #2467
Labels
kind: bug Issues describing general bugs, and PRs fixing them topic: parser

Comments

@fingolfin
Copy link
Member

When reading input, literal sequences exceeding the size of the Value buffer (i.e. more than 1024 characters) are handled by ReadLongNumber in src/read.c. This is broken in several ways. Here are some examples. Warning very long input lines. Naturally.

# integer with 1100 digts: works
gap> 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;;

# overlong identifier starting with a letter: correctly detected
gap> x12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;
Syntax error: Identifiers in GAP must consist of less than 1023 characters.
...

# overlong identifier starting with a digit: wrong error message (identifiers cannot exceed 1023 characters)
gap> gap> 1x2345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;
Error, Variable: '1x2345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901\
23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012\
34567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123\
45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234\
56789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345\
6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901
not in any function at *stdin*:1

# overlong identifier, with first non-digit coming after the 1024 character mark: GAP gets completely confused, ends on continuation prompt
gap> 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890x;
Syntax error: Identifier over 1024 characters
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901\
23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012\
34567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123\
45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234\
56789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345\
67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456\
78901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567\
89012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\
9012345678901234567890123456789012345678901234567890x;
                                                                                                                                   \
                                                                                                                                   \
                                                                                                                                   \
                                                                                                                                   \
                                                                                                                                   \
                                                                                                                                   \
                                                                                                                                   \
                                                                                                                                   \
                                                    ^
Error, Int: Invalid parsing (internal error)
not in any function at *stdin*:
>
@fingolfin fingolfin added the kind: bug Issues describing general bugs, and PRs fixing them label Jan 25, 2017
@fingolfin
Copy link
Member Author

... and you can find more if you e.g. insert periods, which triggers the float code, or records; and can also lead to GAP actually evaluating part of the expression:

# leading period: fine
gap> .12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;
0.123457

# trailing period after more than 1024 digits: fine
gap> 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.;
inf

# leading and trailing period (with more than 1024 digits in between): nonsenes
gap> .12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.;
Syntax error: Record component name expected
.1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901\
23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012\
34567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123\
45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234\
56789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345\
67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456\
78901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567\
89012345678901234567890123456789012345678901234567890.;
                                                                                                                                   \
                                                                                                                                   \
                                                                                                                                   \
                                                                                                                                   \
                                                                                                                                   \
                                                                                                                                   \
                                                                                                                                   \
                                                                                                                                   \
                                                      ^

@ChrisJefferson
Copy link
Contributor

The second error here occurs at much shorter lengths:

gap> .123.;
Syntax error: Record component name expected
.123.;

This is coming in the following way:

  • Parse a float: .123, successfully.
  • We can, given any GAP expression X, try parsing X.y as a record expression.

Technically, we can't even assume that .123.x isn't valid GAP, because a custom float package could turn .123 into a record-type structure!

That's not to say we should improve this error, or stop floats being records.

The same thing occurs parsing 1 . or 1. .

@stevelinton
Copy link
Contributor

You don't need demented custom float packages. Someone could install a method for ELM_REC for IsFloat. You could even imagine wanting x.mantissa and x.exponent to return suitable things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Issues describing general bugs, and PRs fixing them topic: parser
Projects
None yet
3 participants