-
Notifications
You must be signed in to change notification settings - Fork 62
Fix out of bounds access in parse_snippet #165
Conversation
87949a5
to
df1bba0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I think rustc should provide sensible diagnostic spans, we should probably not panic on broken input. So, lgtm
src/lib.rs
Outdated
|
||
// If we get a DiagnosticSpanLine where highlight_end > text.len(), we prevent an 'out of | ||
// bounds' access by using text.len() - 1 instead. | ||
let last_tail_index = if (last.highlight_end - 1) > last.text.len() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let last_tail_index = last.highlight_end.min(last.text.len()) - 1;
should do the same thing.
Do we actually want to validate and fix this? We can also do (I don't mind either way) |
This particular diagnostic from rustc doesn't provide a suggestion anyway and I'm not sure if there are other diagnostics that provide a suggestion and would cause this crash :/ |
I think truncating is fine. We can create a diagnostics json validator later which does a bunch of sanity checks. We can then use that to improve the output generated by rustc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. I'll publish a new version in a minute!
Fixes #164