If a Signal PDU is sent with the data array being a multiple of 4 but the number of samples isn't, when marshall tries to add the padding to buff a java.nio.BufferOverflowException is raised.
The problem is that nrOfBytes is calculated using dataLength/ Byte.Size which in my case samples was 43 and dataLength was 344, but data was a fixed 160 8-bit mu-law buffer.
This is the erroneous section:
```
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;//Padding to hit 32 bit boundry, **if this is not 0 but data.length % 4 == 0, a java.nio.BufferOverflowException is raised. **
switch (paddingBytes) {
case 0:
break;//No padding needed
case 1:
buff.put((byte) 0);
buff.putShort((short) 0);
break;//adding 3 byte padding
case 2:
buff.putShort((short) 0);
break;//adding 2 byte padding
case 3:
buff.put((byte) 0);
break;//adding 1 byte padding
}
If a Signal PDU is sent with the data array being a multiple of 4 but the number of samples isn't, when marshall tries to add the padding to buff a java.nio.BufferOverflowException is raised.
The problem is that nrOfBytes is calculated using dataLength/ Byte.Size which in my case samples was 43 and dataLength was 344, but data was a fixed 160 8-bit mu-law buffer.
This is the erroneous section: