Skip to content
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

Soundness hole in Codegen #6147

Closed
DonIsaac opened this issue Sep 28, 2024 · 0 comments · Fixed by #6148
Closed

Soundness hole in Codegen #6147

DonIsaac opened this issue Sep 28, 2024 · 0 comments · Fixed by #6148
Assignees
Labels
A-codegen Area - Code Generation C-bug Category - Bug

Comments

@DonIsaac
Copy link
Contributor

Codegen::print_char, a public API, can be used to construct invalid UTF-8 in safe code. When Codegen::into_source_text gets called, String::from_utf8_unchecked's invariants will not be upheld, producing undefined behavior.

I do not think this bug is causing any problem in internal oxc crates. However, Codegen and both problematic methods are publically available to anyone using oxc_codegen, and this could introduce unsound code into their projects.

Example:

use oxc::codegen::Codegen;

let mut code = Codegen::new();
code.push_char(0xFF); // past ASCII char boundary for single-byte UTF-8 code points
let invalid = code.into_source_string();
@DonIsaac DonIsaac added C-bug Category - Bug A-codegen Area - Code Generation labels Sep 28, 2024
@DonIsaac DonIsaac linked a pull request Sep 28, 2024 that will close this issue
@DonIsaac DonIsaac self-assigned this Sep 28, 2024
Boshen pushed a commit that referenced this issue Oct 13, 2024
# What This PR Does

Adds `CodeBuffer`, a simple wrapper over a `Vec<u8>` with a protective and reduced API for upholding UTF-8 validity guarantees. Closes #6147.

Note that this struct is actually quite small. Most of the added lines are doc comments.
@Boshen Boshen closed this as completed Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area - Code Generation C-bug Category - Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants