Skip to content

Fix VariableDatum getMarshalledSize() padding calculation - #40

Merged
ricklentz merged 1 commit into
masterfrom
fix/variable-datum-size
Oct 7, 2026
Merged

ricklentz merged 1 commit into
masterfrom
fix/variable-datum-size

Conversation

@ricklentz

Copy link
Copy Markdown
Collaborator

Summary

  • Compute 64-bit boundary padding from accumulated size instead of using padding.length (which is 0 before marshaling)

Problem

getMarshalledSize() returned a size that didn't account for the padding bytes that marshal() writes via Align.to64bits(). When a ByteBuffer is allocated with getMarshalledSize() bytes, marshaling overflows it.

Example: 4-byte datum → getMarshalledSize() returned 12 (4+4+4+0) but marshal() wrote 16 (4+4+4+4 padding).

Test plan

  • VariableDatumTest.testMarshalUnmarshalByteBuffer() should pass
  • All other VariableDatum tests still pass

Fixes #36

getMarshalledSize() used padding.length which is 0 before marshaling.
The ByteBuffer marshal path then writes additional Align.to64bits()
padding bytes, overflowing the pre-allocated buffer.

Compute padding from the accumulated size instead, matching what
Align.to64bits() will write.

Fixes #36
@ricklentz
ricklentz merged commit 800914b into master Oct 7, 2026
1 check passed
@brutzman
brutzman deleted the fix/variable-datum-size branch October 7, 2026 04:20
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.

Java unit test problems with VariableDatumTest and VariableDatum

1 participant