Skip to content

Fix for #185 - #186

Open
minghia wants to merge 2 commits into
open-dis:masterfrom
minghia:master
Open

minghia wants to merge 2 commits into
open-dis:masterfrom
minghia:master

Conversation

@minghia

@minghia minghia commented Jun 17, 2026

Copy link
Copy Markdown
  • ** data array to write to the buffer so that the padding calculation doesn't raise a java.nio.BufferOverflowException.**
  • ** to data length.**
    Made the write to the ByteBuffer use the number of bytes supplied.

     calculation doesn't raise a java.nio.BufferOverflowException.
@leif81 leif81 linked an issue Jun 17, 2026 that may be closed by this pull request
@leif81
leif81 self-requested a review September 12, 2026 19:48
SignalPdu spdu = new SignalPdu();
final int numChunks = 10;
byte[] data = new byte[numChunks];
byte[] data = new byte[numChunks+2];

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.

What is the plus 2?

@minghia minghia Oct 20, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

From memory it was added to test if the data size is a multiple of 4 bytes. The code prior to my change would try and pad the Signal PDU to a 4 bytes boundary. But in the case of the dataLength not being a multiple of 8, the padding code would try and pad past the end of buff.
`int nrOfBytes = 0;
nrOfBytes = dataLength / Byte.SIZE;

buff.put(data);  // This will but the whole data object into buff.  **This should use buff.put(data, 0, nrOfBytes); **
int paddingBytes = nrOfBytes % 4; // and this may not be zero`

The test case was modified to test this case, where the data is not a multiple of 4 bytes but the array containing the data is.

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.

Signal PDU does wrong calculation for the padding bytes in marshal

3 participants