Skip to content

wasi:random: Allow get(-insecure)-random-bytes to return fewer bytes than requested#901

Merged
badeend merged 1 commit intoWebAssembly:mainfrom
badeend:random-max-len
Mar 10, 2026
Merged

wasi:random: Allow get(-insecure)-random-bytes to return fewer bytes than requested#901
badeend merged 1 commit intoWebAssembly:mainfrom
badeend:random-max-len

Conversation

@badeend
Copy link
Member

@badeend badeend commented Mar 10, 2026

Different design to reach the same goal as: #895

@badeend badeend requested a review from a team as a code owner March 10, 2026 20:41
@github-actions github-actions bot added the P-random Proposal: wasi-random label Mar 10, 2026
@ricochet
Copy link
Contributor

LGTM cc @sunfishcode @pchickey @alexcrichton

@badeend
Copy link
Member Author

badeend commented Mar 10, 2026

@pchickey In the previous PR you mentioned:

I think we should change the docs of both p2 and p3 to permit implementations to return less than requested.

The P2 interface doesn't explicitly document any relationship between the input parameter and the returned list. Though, suddenly returning less data is strictly speaking a breaking change.

I've only touched the P3 interface in this PR. Let me know whether it's acceptable to change the P2 intrface too.

@alexcrichton
Copy link
Contributor

My interpretation of wasip2's documentation:

Return len cryptographically-secure random or pseudo-random bytes.

is that by the letter-of-the-law it would be a breaking change to update wasip2's behavior. That being said if it's not like WASIp2 is the most widely deployed platform in the world where changing anything breaks someone, so practically it might be possible to actually implement such a change.

One data point here is that wasi-libc's implementation exits upon receiving too-few bytes. That'll need to change for WASIp3, in which case it's probably pretty easy to do the same for wasip2 as well.

Overall, r+ from me for wasip3, and personally I'd consider changing wasip2 on the table but I wouldn't want to block wasip3.

Another possible hammer to deploy for wasip2 is to deprecate the existing functions in favor of new ones with these new semantics.

@badeend
Copy link
Member Author

badeend commented Mar 10, 2026

wasi-libc's implementation exits upon receiving too-few bytes

Hmm, so even with a sample size=1, we've already found a implementation that will break when returning fewer bytes.
We have pretty direct control over wasi-libc, so it wouldn't be the end of the world.
But let's keep this PR scoped to 0.3 for now, agreed?

@badeend badeend added this pull request to the merge queue Mar 10, 2026
Merged via the queue into WebAssembly:main with commit 053770a Mar 10, 2026
2 checks passed
@badeend badeend deleted the random-max-len branch March 10, 2026 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P-random Proposal: wasi-random

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants