Skip to content

HSLF: reject oversized PersistPtr sheet offsets#1078

Open
metsw24-max wants to merge 1 commit into
apache:trunkfrom
metsw24-max:hslf-persistptr-offset-hardening
Open

HSLF: reject oversized PersistPtr sheet offsets#1078
metsw24-max wants to merge 1 commit into
apache:trunkfrom
metsw24-max:hslf-persistptr-offset-hardening

Conversation

@metsw24-max
Copy link
Copy Markdown
Contributor

Harden HSLF PersistPtr parsing against unsigned-to-signed integer truncation when reading sheet offsets from PersistPtrIncrementalBlock records.

Previously, PersistPtrHolder read 32-bit unsigned sheet offsets using LittleEndian.getUInt(...) and narrowed them with a plain (int) cast. Values larger than Integer.MAX_VALUE wrapped to negative offsets and were stored in _slideLocations.

These wrapped offsets later flowed into Record.buildRecordAtOffset(docstream, offset), where malformed inputs could cause the parser to read records from unintended positions in the document stream instead of rejecting the corrupted input cleanly.

Changes

  • Replaced the narrowing cast with Math.toIntExact(...) when parsing PersistPtr sheet offsets
  • Added an inline hardening comment documenting the threat model and parser impact
  • Preserved support for all valid signed-int offsets, including Integer.MAX_VALUE

Tests

Added regression coverage in TestPersistPtrHolder:

  • testRejectsOversizedSheetOffset

    • Verifies oversized uint32 offsets now fail with ArithmeticException
  • testAcceptsMaxIntSheetOffset

    • Verifies legitimate maximum signed-int offsets continue to parse correctly

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