You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Investigate socket.cpp and buffer.cpp findings in AI code quality #3885
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.
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.
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 );
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.
Activity
softins commentedon Aug 10, 2026
They look valid to me, although the socket.cpp one appears to be offering three different solutions to the same issue. Happy to investigate.
mcfnord commentedon Aug 10, 2026
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.cppfinding text is pasted into this thread, one candidate already has a measured answer.CNetBuf::Putgates validity oniInSize % ( iBlockSize + iNumBytesSeqNum )(buffer.cpp:162) but counts blocks asiInSize / iBlockSize(buffer.cpp:169). Different divisors, so an over-run exists on paper wheneveriInSize / ( iBlockSize + 1 ) >= iBlockSize. It is unreachable in the protocol-valid regime:CELT_MINIMUM_NUM_BYTES = 10forcesiBlockSize >= 9, above the largest frame-size factor of 4. The local path cannot reach lower either — the smallestOPUS_NUM_BYTES_*a client can select is 12 (client.h:115).An ASan fuzz linked against the real
buffer.obuilt from 8b667a3 covered that regime —blockSize9 to 20000,numBlocks1 to 20,factin 1, 2, 4, sequence numbers and stats each on and off, adversarial fills, plus a direct arm feedingPuteveryiInSizefrom 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, trippedheap-buffer-overflow in CNetBuf::Put at buffer.cpp:179on 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.
dingodoppelt commentedon Aug 10, 2026
I've already had a look at that when I worked on the buffer code and the calculation of
iNumBlocksis indeed weird but the comment clearly states/* floor */. Since the sequence number is 1 byte long we'd just add1to 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.softins commentedon Aug 10, 2026
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:
The
/* floor */comment is not needed and doesn't apply, because line 162 has already established thatiInSizeis 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.
ann0see commentedon Aug 15, 2026
Will close this as the PRs. were opened...