Skip to content

Harden InputMemoryStream Bounds Checks Against Integer Overflow#422

Merged
ermig1979 merged 1 commit into
ermig1979:masterfrom
jmestwa-coder:input-stream-overflow-check
Jun 13, 2026
Merged

Harden InputMemoryStream Bounds Checks Against Integer Overflow#422
ermig1979 merged 1 commit into
ermig1979:masterfrom
jmestwa-coder:input-stream-overflow-check

Conversation

@jmestwa-coder

Copy link
Copy Markdown
Contributor

Summary

Harden InputMemoryStream bounds checks against integer overflow when validating read and skip operations.

Changes

  • Replace _pos + size <= _size with the overflow-safe form size <= _size - _pos.
  • Apply the same validation logic to both CanRead() and Skip().
  • Preserve existing behavior for valid inputs while preventing overflow from bypassing bounds checks.

Benefits

  • Prevents integer-overflow-induced bounds check bypasses.
  • Strengthens validation for untrusted image input parsing.
  • Improves memory-safety guarantees across all loaders using InputMemoryStream.
  • Centralizes protection in a shared stream primitive rather than individual decoder paths.

@ermig1979 ermig1979 merged commit c6ef3bd into ermig1979:master Jun 13, 2026
26 checks passed
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