Make multipart upload parsing linear instead of quadratic

CGIFormData::parse() runs again for every 4KB TLS read, and PART_BODY
searched the whole part from its start each time with ZString::find()
(one character at a time), so uploads were quadratic: 1MB took about a
minute and larger camera JPEGs never finished. Track how much of the
current part has already been scanned (partScanned) and memmem() only
the new bytes (backing up by the marker length in case it straddles two
reads).

Adds a member to CGIFormData, so everything that allocates it
(HTTPRequest.cpp) must be rebuilt along with the library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brad ArantandClaude Opus 5.5 committed 2026-11-16 16:10:53 +00:00
1 parent 2cea81c996
commit f5aee23f5e
2 files changed
+21 -3

No files matched your search

+4
View File
@@ -60,6 +60,10 @@ namespace coreutils {
IMFBoundary *boundaryParser = NULL;
MString currentName;
std::map<MString, int> nameCounts;
/// How many bytes of the current part's body (from the cursor) have
/// already been searched for the closing boundary, so each new 4KB
/// TLS read only searches the new bytes (see PART_BODY).
size_t partScanned = 0;
void extractPartName(IMFHeader &header);