This discussion is archived
12 Replies Latest reply: Feb 17, 2013 9:16 AM by 991510 RSS

ArrayIndexOutOfBoundsException, Response.parseString

810935 Newbie
Currently Being Moderated
java.lang.ArrayIndexOutOfBoundsException
     at com.sun.mail.iap.Response.parseString(Response.java:391)
     at com.sun.mail.iap.Response.readString(Response.java:320)
     at com.sun.mail.imap.protocol.ENVELOPE.<init>(ENVELOPE.java:96)
     at com.sun.mail.imap.protocol.FetchResponse.parse(FetchResponse.java:127)
     at com.sun.mail.imap.protocol.FetchResponse.<init>(FetchResponse.java:63)
     ...
Take a look at Response.java
     ...
     b = buffer[index];
     if (b == '"') { // QuotedString
          index++; // skip the quote
          int start = index;
          int copyto = index;

          while ((b = buffer[index]) != '"') {     *** LINE 391
               ...
          }
     }
               We iincrement index, and try to read from buffer without any size checks.
    index++; // skip the quote
    ...
    while ((b = buffer[index]) != '"') {
{code}

So if the quoted string was bad formed, e.g. it terminated right after '"', then we would get ArrayIndexOutOfBoundsException error. While comments state that in case of any error it should return 'null' value instead.
/**
* Generic parsing routine that can parse out a Quoted-String,
* Literal or Atom and return the parsed token as a String
* or a ByteArray. Errors or NIL data will return null.
*/
private Object parseString(boolean parseAtoms, boolean returnString) {
...
}
Notice, that the same issues can be seen in other places. E.g. in following code we can easy go out of bounds if string has no '}'.
while (buffer[index] != '}')
index++;
Whould be great it this code can be reviewed and fixed :-)

Regards,
  - Alex                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  • 1. Re: ArrayIndexOutOfBoundsException, Response.parseString
    796440 Guru
    Currently Being Moderated
    alex2k8 wrote:
    Whould be great it this code can be reviewed and fixed :-)
    Not likely. At least not as a result of your post here. This isn't the channel for reporting bugs, and it's unlikely an Oracle employee in a position to fix it will even see your post.

    Sun used to have a "Bug Parade" or "Bug Database" site for reporting bugs, but I don't know if it's still supported since the transition to Oracle.
  • 2. Re: ArrayIndexOutOfBoundsException, Response.parseString
    810935 Newbie
    Currently Being Moderated
    I hope that Bill Shannon will take a look ;-)
  • 3. Re: ArrayIndexOutOfBoundsException, Response.parseString
    823918 Newbie
    Currently Being Moderated
    try posting this on the kenai bugzilla:

    http://kenai.com/bugzilla/enter_bug.cgi%3Fproduct%3Djavamail

    --Nick

    Edited by: user13479700 on Dec 14, 2010 1:09 PM
  • 4. Re: ArrayIndexOutOfBoundsException, Response.parseString
    bshannon Pro
    Currently Being Moderated
    Yes, JavaMail could do a better job handling this error case.

    Did you actually see this error in practice? Which server?

    I filed a bug for this:
    http://kenai.com/bugzilla/show_bug.cgi?id=3815
    I'll deal with this after JavaMail 1.4.4.
  • 5. Re: ArrayIndexOutOfBoundsException, Response.parseString
    900047 Newbie
    Currently Being Moderated
    We are using GMail's imap servers.
    And we are getting reports from some people getting ArrayOutOfBounds exceptions.

    I cannot reproduce the error as it does not happen for our GMail accounts, but for some other people it does (JavaMail 1.4.4).

    Is there any update on the issue? Just checked out the src at http://kenai.com/projects/javamail/sources/mercurial/content/mail/src/main/java/com/sun/mail/iap/Response.java?rev=386 but seems to be identical to the version we are talking about...


    Thanks :)


    Raphael
  • 6. Re: ArrayIndexOutOfBoundsException, Response.parseString
    bshannon Pro
    Currently Being Moderated
    I'm in the middle of a private conversation with someone who is having this problem. I'm hoping that
    he'll be able to provide enough information about what's going wrong that I can add a workaround
    to JavaMail. Note that this is almost certainly a bug in Gmail.

    If you find a reproducible case, send me details at javamail_ww@oracle.com.
  • 7. Re: ArrayIndexOutOfBoundsException, Response.parseString
    900047 Newbie
    Currently Being Moderated
    Hi ,


    that's pretty cool. A really long time we thought that we are the problem.

    Another problem (maybe related with this issue) is a "no Content" error when doing a com.sun.mail.imap.IMAPMessage.writeTo(IMAPMessage.java:698). Do you think that could be related? This error is also only happening for a tiny subset of users (and does not happen for me or my company).

    How can I assist in debugging. Would a setDebug== true help?

    Session session = Session.getInstance(props);
    session.setDebug(true);

    What specific parts of the debug would help? (Assuming that I have to ask clients to send me their confidential debug logs).

    Any other things that would help?


    Thanks for looking into this :)

    Raphael
  • 8. Re: ArrayIndexOutOfBoundsException, Response.parseString
    bshannon Pro
    Currently Being Moderated
    I've contacted people at Google and they've asked for more information to debug the ArrayIndexOutOfBoundsException problem.
    They'd like a copy of the message and the name of the account containing the message. If you have a reproducible test case,
    please send me these details at javamail_ww@oracle.com.

    For the "no content" problem, I don't know if it's the same problem, a related problem, or a completely different problem.
    Seeing the protocol trace form the debug output would help. I usually only need to see the last few IMAP commands
    in the log before the error occurs. You can send the log to the address above.
  • 9. Re: ArrayIndexOutOfBoundsException, Response.parseString
    bshannon Pro
    Currently Being Moderated
    If anyone is still seeing this exception, I'd love to get the details so I can pass them on to
    Google so they can fix this bug in Gmail.

    Thanks.
  • 10. Re: ArrayIndexOutOfBoundsException, Response.parseString
    991510 Newbie
    Currently Being Moderated
    Hello you who are still alive here,

    2 years have passed and I tried playing with javax.mail 1.4.6-rc1 (along with gimap 1.4.6-rc1).

    The issue appeared for my GMail account while I was trying to test the library.

    bshannon wrote:
    If anyone is still seeing this exception, I'd love to get the details so I can pass them on to
    Google so they can fix this bug in Gmail.

    Thanks.
    buffer seems to contain:

    * * 6606 FETCH (X-GM-LABELS ("\Importantt" Notifications "\\Starred"))

    (the rest of buffer is filled with \0, the HTMLiser of the forum seems to break the string quoted here, the actual buffer is:

    [42, 32, 54, 54, 48, 54, 32, 70, 69, 84, 67, 72, 32, 40, 88, 45, 71, 77, 45, 76, 65, 66, 69, 76, 83, 32, 40, 34, 92, 73, 109, 112, 111, 114, 116, 97, 110, 116, 116, 34, 32, 78, 111, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 115, 32, 34, 92, 92, 83, 116, 97, 114, 114, 101, 100, 34, 41, 41, 13, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    )


    After some tests, it appears this is related to the fact that I attempt to fetch:
    fp.add(GmailFolder.FetchProfileItem.LABELS);
    From my INBOX.

    Let me know if I can be of some help.

    Cheers,
    --
    Pierre.
  • 11. Re: ArrayIndexOutOfBoundsException, Response.parseString
    bshannon Pro
    Currently Being Moderated
    A fix for this was included in the final release of 1.4.6.
    Please try it and let me know if this is still a problem.
  • 12. Re: ArrayIndexOutOfBoundsException, Response.parseString
    991510 Newbie
    Currently Being Moderated
    Impressive. Works perfectly well. Thank you very much for your quick feedback on the issue.

    --
    Pierre.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points