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

Remove size limit for WASI random_get #508

Merged
merged 2 commits into from
Sep 6, 2024
Merged

Conversation

electrum
Copy link
Collaborator

@electrum electrum commented Sep 2, 2024

No description provided.

Copy link
Collaborator

@andreaTP andreaTP left a comment

Choose a reason for hiding this comment

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

A couple of notes but lgtm, having a test would be ideal but not a requirement at this stage.
Thanks!

if (Thread.currentThread().isInterrupted()) {
throw new ChicoryException("Thread interrupted");
}
new SecureRandom().nextBytes(data);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that SecureRandom should be instantiated outside the loop.
It would be ideal to add a "Random source" to the WasiOptions class, I can follow up with the changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea! I'll add another commit.

@electrum
Copy link
Collaborator Author

electrum commented Sep 5, 2024

@andreaTP I updated WasiOptions to accept Random and added a test which verifies that large buffers are handled and that the provided Random is used correctly.

@electrum
Copy link
Collaborator Author

electrum commented Sep 5, 2024

I checked wasi-libc and found that random_get() is only used for getentropy() which is limited to 256 bytes, so the previous limitation won't be an issue in practice, but it's good not to have arbitrary limits in our implementation (perhaps the spec should have a limit).


@Test
public void wasiRandom() {
var seed = 0x12345678;
Copy link
Collaborator

Choose a reason for hiding this comment

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

perfect 👍

@andreaTP andreaTP merged commit 5eb6670 into dylibso:main Sep 6, 2024
13 checks passed
@electrum electrum deleted the random branch September 6, 2024 18:55
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