Skip to content

Validate HDGF v6+ chunk Length before narrowing to int#1075

Merged
pjfanning merged 1 commit into
apache:trunkfrom
metsw24-max:hdgf-validate-v6-chunk-length
May 14, 2026
Merged

Validate HDGF v6+ chunk Length before narrowing to int#1075
pjfanning merged 1 commit into
apache:trunkfrom
metsw24-max:hdgf-validate-v6-chunk-length

Conversation

@metsw24-max
Copy link
Copy Markdown
Contributor

The HDGF v6+ ChunkHeader parser previously narrowed the unsigned 32-bit Length field using a plain (int) cast:

(int) LittleEndian.getUInt(...)

Values larger than Integer.MAX_VALUE silently wrapped to negative numbers and could propagate into chunk offset arithmetic in ChunkFactory.createChunk(...):

offset + getLength() + sizeInBytes

This patch replaces the v6+ Length cast with Math.toIntExact(...), matching the existing v4/v5 handling already used in the same method.

Identifier-style fields (type, id, unknown1) intentionally retain their existing casts. Existing tests already verify that negative reinterpretation is part of the current behavior contract (for example header.getId() == -1 for 0xFFFFFFFF).

Tests

Added regression coverage for:

  • rejecting oversized v6+ Length values (0x80000001)
  • continuing to accept Integer.MAX_VALUE as a valid representable length

@pjfanning pjfanning merged commit e81982e into apache:trunk May 14, 2026
1 check passed
@pjfanning
Copy link
Copy Markdown
Member

thanks - merged

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