Skip to content

fix(parser): don't panic on multibyte char in consecutive comments - #1995

Merged
pront merged 3 commits into
vectordotdev:mainfrom
DeviousCardi:fix/1989-lexer-comment-multibyte-panic
Oct 16, 2026
Merged

pront merged 3 commits into
vectordotdev:mainfrom
DeviousCardi:fix/1989-lexer-comment-multibyte-panic

Conversation

@DeviousCardi

Copy link
Copy Markdown
Contributor

Summary

Since #1946, the lexer panics with start byte index N is not a char boundary on a valid program where a comment directly follows another comment inside a block and the second one has a non-ASCII character (#1989).

Root cause, in delimited_query_char:

  1. It sliced self.input[pos + 1..] before checking whether the character at pos opens a literal. When that character is multi-byte, pos + 1 is not a char boundary. Before chore(lints): remove parser pedantic exceptions #1946 the slice happened only inside the literal branches.
  2. A multi-byte character reaches that point because the comment branch returned the # of an immediately following comment as an ordinary character. The rest of that comment was then scanned one character at a time. This is also why a " in that second comment fails with an unterminated-string error.

Fix:

  • Build the literal lexer only in the ", s', r' and t' branches.
  • After skipping a comment, apply the same rules to the next character (recursively). Back-to-back comments and a literal right after a comment are then skipped as a whole.

How did you test this PR?

  • Added lexer unit tests in src/parser/lex.rs. One covers the multi-byte character in a second consecutive comment, which panicked before this change. The other covers a quote in a second consecutive comment, which returned a lex error before.
  • Added lib/tests/tests/issues/1989_multibyte_char_in_consecutive_comments.vrl, the program from the issue. It panics on main and passes with this change.
  • cargo test --lib --no-default-features --features compiler,stdlib passes (1954 tests). cargo run -p vrl-tests --bin vrl-tests passes (960 passed).
  • cargo fmt and cargo clippy --lib --tests -- -D warnings (compiler,stdlib features) are clean.

This PR was mostly generated with Claude Opus 5.5. I reviewed and tested it.

Does this PR include user-facing changes?

  • Yes. Please add a changelog fragment based on
    our guidelines.
  • No. A maintainer will apply the "no-changelog" label to this PR.

Checklist

References

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y1b55sEL1gA1c3FCMcQCbm

`delimited_query_char` sliced the input at `pos + 1` before checking
whether the character at `pos` opens a literal. When it is a multi-byte
character, `pos + 1` is not a char boundary and the slice panics.

Such a character is reached when a comment directly follows another
comment in a block: the comment branch returned the `#` of the next
comment as an ordinary character, so the rest of that comment was
scanned character by character (and a quote in it was lexed as the
start of a string literal).

Only build the literal lexer in the branches that need it, and after
skipping a comment, scan the following character with the same rules
so consecutive comments and literals are skipped as a whole.

Fixes vectordotdev#1989

Generated with Claude Opus 5.5.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y1b55sEL1gA1c3FCMcQCbm
@DeviousCardi
DeviousCardi requested a review from a team as a code owner October 16, 2026 01:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T18:26:03.805176Z 830245c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac5c6cfe83

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/parser/lex.rs Outdated
DeviousCardi and others added 2 commits October 16, 2026 07:42
Avoid recursing once per comment line in `delimited_query_char`, which
could overflow the stack on long runs of comments in a block.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y1b55sEL1gA1c3FCMcQCbm

@pront pront left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this fix!

@pront
pront added this pull request to the merge queue Oct 16, 2026
Merged via the queue into vectordotdev:main with commit c8908d6 Oct 16, 2026
24 checks passed
@DeviousCardi

Copy link
Copy Markdown
Contributor Author

@pront Thanks for the review, the follow-up commit, and the merge!

@DeviousCardi
DeviousCardi deleted the fix/1989-lexer-comment-multibyte-panic branch October 18, 2026 18:13
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

Successfully merging this pull request may close these issues.

Lexer panics on non-ASCII char in column-0 comment inside a block ("is not a char boundary", lex.rs:923)

2 participants