LANG-1722: Rethrow NegativeArraySizeException as SerializationException in SerilizationUtils.deserialize(InputStream) (#1141)

* LANG-1722: Catch NegativeArraySizeException

Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>

* Fix unit test formatting

Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>

---------

Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
This commit is contained in:
Arthur Chan 2023-12-07 13:44:58 +00:00 committed by GitHub
parent 3760ad0838
commit c3f5f3204b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -207,7 +207,7 @@ public class SerializationUtils {
@SuppressWarnings("unchecked")
final T obj = (T) in.readObject();
return obj;
} catch (final ClassNotFoundException | IOException ex) {
} catch (final ClassNotFoundException | IOException | NegativeArraySizeException ex) {
throw new SerializationException(ex);
}
}

View File

@ -360,4 +360,13 @@ public class SerializationUtilsTest extends AbstractLangTest {
assertThrows(SerializationException.class, () -> SerializationUtils.serialize(iMap, streamTest));
}
@Test
public void testNegativeByteArray() throws IOException {
final byte[] byteArray = {
(byte) -84, (byte) -19, (byte) 0, (byte) 5, (byte) 125, (byte) -19, (byte) 0,
(byte) 5, (byte) 115, (byte) 114, (byte) -1, (byte) 97, (byte) 122, (byte) -48, (byte) -65
};
assertThrows(SerializationException.class, () -> SerializationUtils.deserialize(new ByteArrayInputStream(byteArray)));
}
}