Skip to content

Security: Use of assert statements for input validation in production code#435

Open
tomaioo wants to merge 1 commit into
dask:mainfrom
tomaioo:fix/security/use-of-assert-statements-for-input-valid
Open

Security: Use of assert statements for input validation in production code#435
tomaioo wants to merge 1 commit into
dask:mainfrom
tomaioo:fix/security/use-of-assert-statements-for-input-valid

Conversation

@tomaioo
Copy link
Copy Markdown

@tomaioo tomaioo commented May 26, 2026

Summary

Security: Use of assert statements for input validation in production code

Problem

Severity: Medium | File: dask_image/ndfourier/_utils.py:L18

The file dask_image/ndfourier/_utils.py uses Python assert statements for input validation (e.g., lines checking issubclass(dtype, numbers.Real)). Assert statements can be disabled globally when Python is run with the -O (optimize) flag, which would bypass these checks entirely. This could allow invalid inputs to propagate through the code, potentially causing crashes, incorrect results, or undefined behavior in production environments where optimized Python execution is used.

Solution

Replace assert statements with proper if conditions that raise appropriate exceptions (e.g., ValueError, TypeError). For example, instead of assert (issubclass(dtype, numbers.Real) and not issubclass(dtype, numbers.Integral)), use if not (issubclass(dtype, numbers.Real) and not issubclass(dtype, numbers.Integral)): raise TypeError("dtype must be a non-integral real number").

Changes

  • dask_image/ndfourier/_utils.py (modified)

The file `dask_image/ndfourier/_utils.py` uses Python `assert` statements for input validation (e.g., lines checking `issubclass(dtype, numbers.Real)`). Assert statements can be disabled globally when Python is run with the `-O` (optimize) flag, which would bypass these checks entirely. This could allow invalid inputs to propagate through the code, potentially causing crashes, incorrect results, or undefined behavior in production environments where optimized Python execution is used.

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
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