Let's say a highly sensitive codebase has the following check:
public Something(byte[] content) {
if (content.length != 20) {
throw new RuntimeException("length is invalid");
}
// do something critical with content
And the constructor Something is called like this:
ByteArrayOutputStream a = new ByteArrayOutputStream();
// fill the byte array as you want
...
// call the highly sensitive constructor
Something(a.toByteArray());
Is it possible -granted enough memory- to fill the ByteArrayOutputStream with 2*Integer.MAX_VALUE + 20, so that the comparison of the array's length with 20 is valid?
I have found this article about the theoretical limit of array lengths upon their creation, but I wonder if there is an edge case when converting from unbounded data structure like ... or streams to byte arrays (like returned by the toByteArray of ByteArrayOutputStream class).