Skip to content

Fix: Add input validation for XOR Checksum blocksize (#2537)#2542

Open
dweep-js wants to merge 2 commits into
gchq:masterfrom
dweep-js:patch-1
Open

Fix: Add input validation for XOR Checksum blocksize (#2537)#2542
dweep-js wants to merge 2 commits into
gchq:masterfrom
dweep-js:patch-1

Conversation

@dweep-js

@dweep-js dweep-js commented Jun 9, 2026

Copy link
Copy Markdown

Description
This pull request adds input validation to the XOR Checksum operation (src/core/operations/XORChecksum.mjs). Previously, entering a decimal (float) or a negative value as the Blocksize parameter would pass straight to the JavaScript array constructor (Array(blocksize)), triggering an uncaught RangeError: invalid array length and crashing the application's runtime.

This fix introduces an explicit check using Number.isInteger() and bounds validation (<= 0) right at the start of the run method. If the user passes an invalid block size, it now gracefully interrupts execution and throws a user-friendly OperationError, displaying a clear error message in the output panel instead of crashing.

Existing Issue
Fixes #2537

Screenshots

  • Before: Entering 1.1 or -1 causes a frozen screen or a blank output box, with a red RangeError appearing in the browser's developer console.
  • After: Entering 1.1 or -1 immediately shows a clean, red error banner in the output pane stating: Blocksize must be a positive integer.

Test Coverage
Tested manually via the local web server (localhost:8080) using the exact inputs from the bug report:

  1. Input: 1.1 -> Successfully caught by validation, shows Blocksize must be a positive integer.
  2. Input: -1 -> Successfully caught by validation, shows Blocksize must be a positive integer.
  3. Input: 4 (Valid integer) -> Runs successfully without errors, matching original expected behavior.

dweep-js added 2 commits June 9, 2026 18:51
Added validation for blocksize and imported OperationError for error handling. fixes Issue gchq#2537.
@dweep-js dweep-js closed this Jun 10, 2026
@dweep-js dweep-js reopened this Jun 10, 2026
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.

bug(XOR Checksum): a float or negative block size cause an uncaught RangeError

1 participant