Skip to content

Guard Ole10Native readUtf16 byte length against int overflow#1080

Open
jmestwa-coder wants to merge 1 commit into
apache:trunkfrom
jmestwa-coder:ole10native-utf16-overflow
Open

Guard Ole10Native readUtf16 byte length against int overflow#1080
jmestwa-coder wants to merge 1 commit into
apache:trunkfrom
jmestwa-coder:ole10native-utf16-overflow

Conversation

@jmestwa-coder
Copy link
Copy Markdown
Contributor

Found while fuzzing Ole10Native record parsing. readUtf16 reads a 32-bit char count and hands size * 2 to IOUtils.toByteArray; a count near 0x40000000 makes that product overflow to a negative int, which slips past the MAX_STRING_LENGTH cap so an oversized record surfaces a raw IllegalArgumentException from getFromUnicodeLE rather than the RecordFormatException the cap is meant to raise. Compute the byte count as size * 2L so the long overload applies the cap before narrowing.

RecordFormatException.class,
() -> new Ole10Native(data, 0)
);
assertTrue(ex.getMessage().contains("Tried to allocate"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use POITestCase assertContains

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