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

chore(serde_v8): throw error when string buffer exceeds v8 max length #14588

Merged
merged 9 commits into from
May 26, 2022
Merged

chore(serde_v8): throw error when string buffer exceeds v8 max length #14588

merged 9 commits into from
May 26, 2022

Conversation

GJZwiers
Copy link
Contributor

@GJZwiers GJZwiers commented May 12, 2022

When using TextDecoder on very large data (> 512MB) Rust will panic, because the buffer passed to v8::String::new_from_two_byte exceeds v8::String::max_length. This PR adds a more descriptive error message in case this happens.

Related to #13648

before:

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', serde_v8\magic\u16string.rs:16:10

after:

error: Uncaught (in promise) TypeError: Error serializing return: Cannot allocate String from UTF-16: buffer exceeds maximum length.

@GJZwiers GJZwiers changed the title chore: improve panic! message when string buffer exceeds v8 limit chore(serde_v8): improve panic! message when string buffer exceeds v8 limit May 12, 2022
@GJZwiers GJZwiers marked this pull request as ready for review May 13, 2022 10:24
@GJZwiers GJZwiers requested a review from AaronO as a code owner May 13, 2022 10:24
@lucacasonato
Copy link
Member

Ideally this doesn't panic at all, but gracefully errors. @AaronO WDYT?

@bartlomieju
Copy link
Member

Ideally this doesn't panic at all, but gracefully errors. @AaronO WDYT?

I agree, it should be an error

@GJZwiers GJZwiers changed the title chore(serde_v8): improve panic! message when string buffer exceeds v8 limit chore(serde_v8): throw error when string buffer exceeds v8 limit May 15, 2022
@GJZwiers GJZwiers changed the title chore(serde_v8): throw error when string buffer exceeds v8 limit chore(serde_v8): throw error when string buffer exceeds v8 max length May 15, 2022
@GJZwiers
Copy link
Contributor Author

I've updated the code to throw an Err instead

@cjihrig
Copy link
Contributor

cjihrig commented May 15, 2022

Can you add a test please.

if let Some(v) = maybe_v {
Ok(v.into())
} else {
Err(Error::Message(String::from(
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably worth including a comment here stating that new_from_two_byte() only fails if the buffer length is greater than kMaxLength.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@AaronO
Copy link
Contributor

AaronO commented May 16, 2022

Ideally this doesn't panic at all, but gracefully errors. @AaronO WDYT?

Yeah, I'll do a pass soon™️ removing all of serde_v8's unwraps (besides tests/benches/examples) either passing through errors or adding .expect() panic messages.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

Thanks @GJZwiers!

@bartlomieju bartlomieju merged commit ab9c7f5 into denoland:main May 26, 2022
@GJZwiers GJZwiers deleted the improve_string_buffer_max_length_error branch May 27, 2022 11:29
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.

None yet

5 participants