Global: fixes issues found by AI

This commit is contained in:
李通洲
2026-09-24 21:21:02 +08:00
committed by Carter Li
parent 00ccd8be12
commit bba45429ae
24 changed files with 387 additions and 80 deletions
+9 -3
View File
@@ -466,7 +466,10 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf
return "Response too large";
}
FF_DEBUG("Receive buffer is full, extending it");
ffStrbufEnsureFreeNoCheck(buffer, buffer->allocated);
// Asking for exactly the room that is left under the cap, rather than for as much as
// the buffer holds again: the allocation is rounded up to a power of two, so a doubling
// from a size that is not one of those lands past the cap the check above just cleared.
ffStrbufEnsureFreeNoCheck(buffer, FF_NETWORKING_MAX_RESPONSE_SIZE - buffer->length - 1);
}
// When the remaining length is known, ask for exactly that much. MSG_WAITALL then
@@ -589,7 +592,7 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf
return "No HTTP header end found";
}
if (chunked && !ffNetworkingDecodeChunked(buffer, headerEnd)) {
if (chunked && !ffNetworkingDecodeChunked(buffer, &headerEnd)) {
return "Failed to decode chunked response";
}
@@ -599,7 +602,10 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf
}
FF_DEBUG("Received valid HTTP 200 response, content %u bytes, total %u bytes", contentLength, buffer->length);
if (contentLength > 0 && buffer->length != contentLength + headerEnd + 4) {
// A chunked response was framed by its last-chunk and has been rewritten around it, so any
// `Content-Length` the server also sent describes a body that no longer exists. RFC 9112 6.3
// says not to send both; when one does, the chunked framing is the one that was acted on.
if (!chunked && contentLength > 0 && buffer->length != contentLength + headerEnd + 4) {
FF_DEBUG("Received content length mismatches: %u != %u", buffer->length, contentLength + headerEnd + 4);
return "Content length mismatch";
}