Skip to content

Potentail unsound issue in libsql-sqlite3-parser #2052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
CXWorks opened this issue May 5, 2025 · 2 comments
Open

Potentail unsound issue in libsql-sqlite3-parser #2052

CXWorks opened this issue May 5, 2025 · 2 comments

Comments

@CXWorks
Copy link

CXWorks commented May 5, 2025

Hi, thanks for your time to read this issue. We cannot find a repo for this crate, so we report the issue here. If it's not the correct place, plet let us know.

Our static analyzer find a potential unsound issue in the utf-8 parsing, where it doesn't provide enough check to ensure the soundness.

fn from_bytes(bytes: &[u8]) -> String {
unsafe { str::from_utf8_unchecked(bytes).to_owned() }
}

A potentail PoC code is like:

use libsql_sqlite3_parser::lexer::sql::{Parser, Tokenizer};
use fallible_iterator::FallibleIterator;


fn main() {
    let invalid_utf8: &[u8] = &[0xC0, 0x80]; 
    let sql = "SELECT ? ";
    let mut v = Vec::new();
    v.extend_from_slice(sql.as_bytes());
    v.extend_from_slice(invalid_utf8);
    let mut parser = Parser::new(&*v);
    let mut cmd = parser.next().unwrap();
    println!("{:?}", cmd)
}

Thanks again for your time.

@CXWorks
Copy link
Author

CXWorks commented May 7, 2025

Sorry, reported at gwenn/lemon-rs#86

@CXWorks CXWorks closed this as completed May 7, 2025
@CXWorks
Copy link
Author

CXWorks commented May 9, 2025

Please check the discussion(gwenn/lemon-rs#86) for details, thanks!

@CXWorks CXWorks reopened this May 9, 2025
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

No branches or pull requests

1 participant