Skip to content

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

Open
Mrmaxmeier wants to merge 4 commits intoapache:mainfrom
Mrmaxmeier:fix-panics
Open

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

Conversation

@Mrmaxmeier
Copy link
Copy Markdown

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
Author

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 because of my input generation experiments.

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