Commit c86994c
authored
fix: rsonpath-syntax error messages blowing up on long inputs (#842)
* fix: rsonpath-syntax error messages blowing up on long inputs
Previously, when displaying a ParseError every underlying
SyntaxError would be printed with the full query input as context.
If the density of errors in the input was high this would effectively
cause a quadratic blowup during printing.
It's probably unlikely inputs like this would be given by a user,
but they do happen during fuzzing (when we're throwing long strings
of essentially random characters at the parser) and could potentially
be used as a DoS attack vector (intentionally supplying nonsensical
large queries and forcing error messages to be sent back).
Any SyntaxError contains the actual error span
(which gets underlined in the output message) and the rest of the
input is displayed as context. We will call the part before
the error the *pre-context*, the part after the *post-context*,
and the error part the *underline*.
We alleviate the quadratic blowup in two ways. First, in multiline
input we now only display the lines that contain the underline.
Second, if the first (or last) line of the error is excessively
long and would print a very large pre-context (or post-context),
we truncate the context by force to keep the total line length
under a reasonable limit (`error::display::MAX_ERROR_LINE_WIDTH`).
Crucially, the SyntaxErrors never overlap, i.e. the underline
parts are always disjoint. The fixes therefore guarantee that
we will output at most the entire input, plus some constant
overhead per error (limited by `MAX_ERROR_LINE_WIDTH`).
The logic to accomplish this is non-trivial, so now we have quite
a bit of code dedicated to this rather exotic edge-case.
Nonetheless, it ultimately makes the error reporting much more
robust.
Additionally fixed an invalid error message given when a side of
a comparison operator was a non-singular query.
This is part of the investigation into fuzzing failures tracked
at #749.1 parent 2f28704 commit c86994c
File tree
14 files changed
+2782
-848
lines changed- crates/rsonpath-syntax
- examples
- src
- error
- tests
- snapshots
14 files changed
+2782
-848
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | | - | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
12 | 20 | | |
13 | | - | |
| 21 | + | |
14 | 22 | | |
15 | 23 | | |
16 | 24 | | |
| |||
0 commit comments