Skip to content

Fix panic in EscapeQuotedString and parse_flush, clean up a few unwraps#2330

Merged
iffyio merged 4 commits intoapache:mainfrom
Mrmaxmeier:fix-panics
May 6, 2026
Merged

Fix panic in EscapeQuotedString and parse_flush, clean up a few unwraps#2330
iffyio merged 4 commits intoapache:mainfrom
Mrmaxmeier:fix-panics

Conversation

@Mrmaxmeier
Copy link
Copy Markdown
Contributor

Hi,
I tried generating SQL inputs with sqlparser and ran into a few crashes. In the process of fixing these, I've also refactored some of the code in ast/ to avoid unwraps where applicable.
Let me know if I should add tests for the two commits that actually change behaviour.
Thanks!

Replace if x.is_some() { x.as_ref().unwrap() }
with if let Some(x) = x { x }
This could previously panick with multi-byte utf8 characters:

datafusion-sqlparser-rs-896df239ce2264c8/847ddf3/src/ast/value.rs:583:53:
end byte index 271 is not a char boundary; it is inside '�' (bytes 270..273 of string)
Comment thread src/ast/value.rs
// Including idx in the range, so the quote at idx will be printed twice:
// in this call to write_str() and in the next one.
f.write_str(&self.string[start_idx..=idx])?;
let end_idx = idx + ch.len_utf8();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could we add a test case that fails without this fix?

Copy link
Copy Markdown
Contributor Author

@Mrmaxmeier Mrmaxmeier May 5, 2026

Choose a reason for hiding this comment

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

Sure, I've added a test. Notably though, this crash is not reachable with normal sqlparser usage because escape_quoted_string is only called with ASCII quote chars. I've only encountered this due to the way I'm using sqlparser for my input generation experiments.

Copy link
Copy Markdown
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @Mrmaxmeier!

@iffyio iffyio added this pull request to the merge queue May 6, 2026
Merged via the queue into apache:main with commit 3f347e3 May 6, 2026
10 checks passed
@Mrmaxmeier Mrmaxmeier deleted the fix-panics branch May 6, 2026 11:06
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.

2 participants