Description
RandomStringUtils.random() can overflow and return characters that are outside the range specified by the start and end parameters. This is because it casts a random integer in the range [start,end) to a character, without checking if this will overflow.
Example failing test case:
@Test public void testCharOverflow() throws Exception { int start = 65535; int end = Integer.MAX_VALUE; @SuppressWarnings("serial") Random fixedRandom = new Random() { @Override public int nextInt(int n) { // Prevents selection of 'start' as the character return 1; } }; String result = RandomStringUtils.random(1, start, end, false, false, null, fixedRandom); char c = result.charAt(0); assertTrue(c >= start && c < end); }