[QFJ-687] Lost message on package fragmentation at 12 bytes in a FIXT.1.1 message Created: 12/Jun/12  Updated: 04/Sep/12  Resolved: 04/Sep/12

Status: Closed
Project: QuickFIX/J
Component/s: Engine
Affects Version/s: 1.5.2
Fix Version/s: None

Type: Bug Priority: Default
Reporter: Jonas Fügedi Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: encoding

Issue Links:
Relates
relates to QFJ-544 Header with BeginString=FIXT.1.1 inco... Resolved

 Description   

The begin string header will be incorrectly detected if a FIXT.1.1 message is fragmented at 12 bytes and a message will be lost with a message regarding bad message length.

    /**
     * Checks to see if the byte_buffer[buffer_offset] starts with data[]. The
     * character ? is a one byte wildcard, lowercase letters are optional.
     *
     * @param pBuffer
     * @param pBufferOffset
     * @param pData
     * @return
     */
    public static int startsWith(ByteBuffer pBuffer, int pBufferOffset, byte[] pData) {
        if (pBufferOffset + minMaskLength(pData) > pBuffer.limit()) {
            return -1;
        }
        final int tInitOffset = pBufferOffset;
        int tDataOffset = 0;
        for (int tBufferLimit = pBuffer.limit();
            (tDataOffset < pData.length) && (pBufferOffset < tBufferLimit);
            tDataOffset++, pBufferOffset++)
        {
            if (pBuffer.get(pBufferOffset) != pData[tDataOffset] && pData[tDataOffset] != '?') {
                // Now check for optional characters, at this point we know we didn't
                // match, so we can just check to see if we failed a match on an optional character,
                // and if so then just rewind the buffer one byte and keep going.
                if (Character.toUpperCase(pData[tDataOffset]) == pBuffer.get(pBufferOffset)) {
                    continue;
                }
                // Didn't match the optional character, so act like it was not included and keep going
                if (Character.isLetter(pData[tDataOffset]) && Character.isLowerCase(pData[tDataOffset])) {
                    --pBufferOffset;
                    continue;
                }
                return -1;
            }
        }
        if (tDataOffset < pData.length) {
            // the buffer was consumed but not the whole mask
            return -1;
        }
        return pBufferOffset - tInitOffset;
    }


 Comments   
Comment by Jonas Fügedi [ 12/Jun/12 ]

The code provided shows my fix where if the whole mask is not consumed then -1 is returned

Comment by Jonas Fügedi [ 12/Jun/12 ]

Oops, copy paste bug... the variable names are wrong, won't compile

        if (dataOffset < data.length) {
            // the buffer was consumed but not the whole mask
            return -1;
        }
Comment by Christoph John [ 15/Aug/12 ]

This looks like QFJ-544. Can you confirm that the issue is fixed by that ticket?

Comment by Jonas Fügedi [ 20/Aug/12 ]

Yes, QFJ-544 seems to cover the same issue. This fix only covered part of the fragmentation issues though, so further issues remain in the same problem area.

Comment by Christoph John [ 20/Aug/12 ]

Sorry, I do not understand fully. Do you mean that the fix you posted covered only part of the problem or the fix in QFJ-544? Are there still open problems or can this (QFJ-687) ticket be closed?

Thanks

Comment by Jonas Fügedi [ 03/Sep/12 ]

This can be closed, the QFJ-544 patch seems to resolve all the issues (I have not run thorough garbled message testing and verified that parser recovery is correct, but valid messages are correct in all my fragmentation scenarios).

Generated at Thu May 02 03:42:36 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.