Skip to content

Fix size validation in sampleSizeWithSeed - #1250

Open
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/sample-size-validation
Open

Fix size validation in sampleSizeWithSeed#1250
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/sample-size-validation

Conversation

@pavankumar-vh

Copy link
Copy Markdown

Overview

Fix size validation in the sampleSizeWithSeed function in common/src/util/random.ts.

Bug Description

The function didn't validate that size is a non-negative integer. If size was NaN, negative, or not an integer, result.slice(0, size) could behave unexpectedly.

Fix

Added Number.isFinite() and size >= 0 checks to default to 0 for invalid sizes.

Testing

No existing tests for this function, but the fix prevents unexpected behavior with invalid inputs.

Files Changed

  • common/src/util/random.ts - Added size validation

Scope

This change only touches common/ which is an approved contribution area per the Contributing Guide.

The function didn't validate that size is a non-negative integer. If size was
NaN, negative, or not an integer, result.slice(0, size) could behave unexpectedly.

Added Number.isFinite() and size >= 0 checks to default to 0 for invalid sizes.
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.

1 participant