Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
None
-
None
-
None
Description
In `EndianUtils` class, the method for handling swappedShort / swappedInteger / swappedLong from or to byte array assumes that the byte array still has enough space or data with the provided offset for an Integer / Long / Short reading or writing. Thus a byte array with a much shorter length could make the code throw IndexOutOfBoundsException. A possible fix is adding a validation to ensure the byte array has enough data space before processing.
Some example code snippets are attached below.
public static void writeSwappedInteger(final byte[] data, final int offset, final int value) { data[offset + 0] = (byte) (value >> 0 & 0xff); data[offset + 1] = (byte) (value >> 8 & 0xff); data[offset + 2] = (byte) (value >> 16 & 0xff); data[offset + 3] = (byte) (value >> 24 & 0xff); }
public static int readSwappedUnsignedShort(final byte[] data, final int offset) { return ((data[offset + 0] & 0xff) << 0) + ((data[offset + 1] & 0xff) << 8); }
Attachments
Issue Links
- links to