Uploaded image for project: 'QuickFIX/J'
  1. QuickFIX/J
  2. QFJ-666

FIXMessageEncoder got BufferOverflowException when encoding fix mesage

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Default
    • Resolution: Duplicate
    • Affects Version/s: 1.5.0
    • Fix Version/s: None
    • Component/s: Engine
    • Environment:
      windows server 2003
      Java Hotspot VM build 1.6.0_29-b11

      Description

      Hi All, I add the code below into my quickfix app, hoping that it could send fix message with multibytes character, such as Chinese.
      CharsetSupport.setCharset("GBK");

      But I found it failed to send out the fix execution report and throws a BufferOverflowException in method encode of quickfix.mina.message.FIXMessageEncoder.
      Below is the code fragment in method encode:

      ByteBuffer buffer = ByteBuffer.allocate(fixMessageString.length());
      try

      { buffer.put(fixMessageString.getBytes(charsetEncoding)); }

      catch (UnsupportedEncodingException e)

      { throw new ProtocolCodecException(e); }

      BufferOverflowException is thrown by the code "buffer.put".
      The reason is String.length() only return the count of character. For multibytes char, String.length() is half smaller than String.getBytes().length, so the capacity of ByteBuffer is not sufficient for the encoded bytes of the fixMessageString.
      Although there is rarely multibytes char in fix message, it can be improved like the below:
      ByteBuffer buffer = null;
      try { byte[] encodedBytes = fixMessageString.getBytes(charsetEncoding) buffer = ByteBuffer.allocate(encodedBytes.length); buffer.put(encodedBytes); } catch (UnsupportedEncodingException e) { throw new ProtocolCodecException(e); }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                frozen007 Zhao Mingyu
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: