Use String::RawSizeMaxXXX() to limit String length#2456
Open
somecookie wants to merge 10 commits into
Open
Conversation
rousskov
approved these changes
Jul 7, 2026
rousskov
left a comment
Contributor
There was a problem hiding this comment.
Thank you for this cleanup and a careful evaluation of Squid code to find all String::RawSizeMaxXXX() candidates.
| * at least 8000 octets for the whole line, including method and version. | ||
| */ | ||
| const size_t maxUriLength = static_cast<size_t>((64*1024)-1); | ||
| const size_t maxUriLength = String::RawSizeMaxXXX(); |
Contributor
There was a problem hiding this comment.
I support the removal of the stale comment above. A part of that comment no longer matches Squid code -- 64KB is not the current String limit. Another part cites a now-obsolete RFC (and is already marked not to "matter"). Using String::RawSizeMaxXXX() makes this code self-documenting (among other advantages).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This replacement aligns Ftp::Server with Ftp::Client code after recent
commit 0a261cb that introduced reusable
String::RawSizeMaxXXX()function for limiting the length of input tokens that may be converted
to String objects. This change effectively doubles the previously
anonymous 32KB limit for received FTP command parts (assuming
request_header_max_sizeis using 64KB default or a larger value).String::RawSizeMaxXXX()classifies the increased limit as safe.Also replaced anonymous 32KB limit in HTTP
X-Forwarded-Forrequestheader field building code, for the same reason.
No other suitable replacement candidates are known in current code. The
following seemingly similar hard-coded limits serve other purposes; they
would be needed even after the
Stringclass is gone from Squid code:similar Store swap metadata iteration code uses raw memory pointers,
not String. UnpackNewSwapMetaVaryHeaders() uses SBuf, not String.
TeChunkedParser::mimeHeaderBlock_storage. The hard-coded limitprevents excessive trailer fields accumulation. Other grabMimeBlock()
callers already use admin-configurable limits that may exceed 64KB.
This is a Measurement Factory project.