Skip to content

Clarification request: findfirstFSync() reads 4 bytes when dataBlockSize < 4 in split FSYNC test #83

@awmorgan

Description

@awmorgan

Hello,

I am looking for clarification on the expected behavior of the FSYNC detection logic in the OpenCSD frame deformatter when the input stream is provided in small chunks.

While analyzing subtest 2 of runHSyncFSyncTest() in frame_demux_test.cpp:

// test fsync broken across 2 input blocks
printSubTestName(2, "HSyncFSync split frame");
resetDecoder(failed);
checkDataPathValue(
    pDecoder->TraceDataIn(OCSD_OP_DATA, index, 2, buf_hsync_fsync, &processed),
    failed);

I observed the following behavior inside TraceFmtDcdImpl::findfirstFSync():

When m_in_block_size == 2, the (m_in_block_size - 3)) is 0xffffffff due to unsigned underflow, causing the loop to execute even though fewer than 4 bytes are available. Inside the loop, a 4-byte load is performed: if (*((uint32_t *)(dataPtr)) == FSYNC_PATTERN) even though the current TraceDataIn() call only provided 2 bytes.

uint32_t TraceFmtDcdImpl::findfirstFSync()
{
    uint32_t processed = 0;
    const uint32_t FSYNC_PATTERN = 0x7FFFFFFF;    // LE host pattern for FSYNC	 
    const uint8_t *dataPtr = m_in_block_base;

    while (processed < (m_in_block_size - 3))
    {
        if (*((uint32_t *)(dataPtr)) == FSYNC_PATTERN)
        {
            m_frame_synced = true;
            break;
        }
        processed++;
        dataPtr++;
    }
    return processed;

Is findfirstFSync() expected to be able to read beyond the provided dataBlockSize?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions