Skip to content

Conversation

@marty1885
Copy link
Collaborator

@marty1885 marty1885 commented Dec 11, 2025

Fallback CSPRNG on generic UNIX will read urandom for randomness. The read has a bug where if fread reads say 10 bytes but the size is 32. The buffer is only partially updated and returned successful.

This patch ensures the fallback read returns success only when the buffer is fully filled.

And moving from ms to us resolution for fallback platform because most platforms will have that. ns is more arguable.

Fallback CSPRNG on generic UNIX will read `urandom` for randomness. The read has a bug where if `fread` reads say 10 bytes but the size is 32. The buffer is only partially updated and returned successful.

This patch ensures the fallback read returns success only when the buffer is fully filled.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug in the fallback CSPRNG implementation for generic UNIX systems and improves the time resolution for entropy collection. The original fread check incorrectly returned success when ANY bytes were read, even if the buffer was only partially filled, potentially leaving random data incomplete and compromising security.

  • Fixed the fread return value check to ensure the buffer is fully filled before returning success
  • Improved time resolution from milliseconds to microseconds for better entropy on fallback platforms

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@marty1885 marty1885 requested a review from an-tao December 11, 2025 16:18
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