Skip to content

Signal PDU does wrong calculation for the padding bytes in marshal #185

Description

@minghia

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
    }

Tony

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions