Skip to content

Apply allocation bounds checks to EmfPolyDraw and WmfCreateRegion#1107

Merged
pjfanning merged 2 commits into
apache:trunkfrom
sahvx655-wq:allocation-bounds-checks
Jun 3, 2026
Merged

Apply allocation bounds checks to EmfPolyDraw and WmfCreateRegion#1107
pjfanning merged 2 commits into
apache:trunkfrom
sahvx655-wq:allocation-bounds-checks

Conversation

@sahvx655-wq
Copy link
Copy Markdown
Contributor

EmfPolyDraw and WmfCreateRegion allocate arrays directly from count fields read from the input stream.

This change applies POI's existing allocation safety checks before the following count-driven allocations:

Point arrays in EmfPolyDraw
Scan object arrays in WmfCreateRegion

Invalid, excessively large, or negative counts are now rejected through POI's standard allocation validation path instead of attempting unchecked array allocations.

Tests

Added regression tests covering:

Integer.MAX_VALUE count in EmfPolyDraw
Negative count in WmfCreateRegion

These tests verify that malformed inputs are rejected before array allocation occurs.

Executed the automated unit tests:

./gradlew :poi-scratchpad:test -PjdkVersion=17

Copy link
Copy Markdown
Member

@pjfanning pjfanning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@pjfanning pjfanning merged commit c60d265 into apache:trunk Jun 3, 2026
1 check 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