Skip to content

[V4] Replace overflow exceptions with explicit size limits - #3287

Merged
JimBobSquarePants merged 1 commit into
release/4.1.xfrom
js/v4-overflow-limits
Nov 26, 2026
Merged

JimBobSquarePants merged 1 commit into
release/4.1.xfrom
js/v4-overflow-limits

Conversation

@JimBobSquarePants

Copy link
Copy Markdown
Member

Summary

This PR backports the size-limit fixes to release/4.1.x.

  • Encoders check each 32-bit format field before they write it and throw ImageFormatException. This applies to ICO and CUR offsets, ANI and WebP RIFF chunk sizes, the WebP file size, TIFF offsets and entry counts, and EXIF value lengths.
  • Allocation lengths throw InvalidMemoryOperationException. This applies to TIFF tag values, the PNG scanline and IPTC text, and the resize kernel row. The kernel row length could wrap and corrupt memory.
  • Resize computes its window in 64 bits and frees its buffers when its constructor fails.
  • SwapOrCopyContent keeps the destination stride for a same-size copy into wrapped memory.
  • WrapMemory checks the height of the byte-stride overloads.

Tests

The full suite passes on net8.0 and net10.0.

Encoders check each 32-bit format field before they write it and throw ImageFormatException:
ICO and CUR offsets, ANI and WebP RIFF chunk sizes, the WebP file size, TIFF offsets and entry
counts, and EXIF value lengths. Allocation lengths throw InvalidMemoryOperationException: TIFF tag
values, the PNG scanline and IPTC text, and the resize kernel row, which could wrap and corrupt
memory. Resize computes its window in 64 bits and frees its buffers when its constructor fails.
SwapOrCopyContent keeps the destination stride for a same-size copy into wrapped memory.
WrapMemory checks the height of the byte-stride overloads.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant