8129544: ArrayIndexOutOfBoundsException when decoding corrupt Base64 string

To take input bytes as unsigned before check range

Reviewed-by: alanb
This commit is contained in:
Xueming Shen 2015-06-24 11:15:23 -07:00
parent fe481eaf1f
commit b46a6500b0
2 changed files with 12 additions and 3 deletions

View File

@ -737,7 +737,7 @@ public class Base64 {
// anything left is invalid, if is not MIME.
// if MIME, ignore all non-base64 character
while (sp < sl) {
if (isMIME && base64[src[sp++]] < 0)
if (isMIME && base64[src[sp++] & 0xff] < 0)
continue;
throw new IllegalArgumentException(
"Input byte array has incorrect ending byte at " + sp);

View File

@ -23,7 +23,7 @@
/**
* @test 4235519 8004212 8005394 8007298 8006295 8006315 8006530 8007379 8008925
* 8014217 8025003 8026330 8028397
* 8014217 8025003 8026330 8028397 8129544
* @summary tests java.util.Base64
* @key randomness
*/
@ -408,7 +408,16 @@ public class TestBase64 {
}});
}
}
}
// anything left after padding is "invalid"/IAE, if
// not MIME. In case of MIME, non-base64 character(s)
// is ignored.
checkIAE(new Runnable() { public void run() {
Base64.getDecoder().decode("AA==\u00D2"); }});
checkIAE(new Runnable() { public void run() {
Base64.getUrlDecoder().decode("AA==\u00D2"); }});
Base64.getMimeDecoder().decode("AA==\u00D2");
}
private static void testDecodeUnpadded() throws Throwable {
byte[] srcA = new byte[] { 'Q', 'Q' };