Use String::RawSizeMaxXXX() to limit String length#2456
Closed
somecookie wants to merge 13 commits into
Closed
Conversation
rousskov
previously 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).
kinkie
reviewed
Jul 9, 2026
Co-authored-by: Francesco Chemolli <5175948+kinkie@users.noreply.github.com>
rousskov
previously approved these changes
Jul 9, 2026
Contributor
|
@somecookie, applying those out-of-scope changes broke formatting. Please reformat (which means more unnecessary line changes; sigh). |
rousskov
approved these changes
Jul 10, 2026
kinkie
approved these changes
Jul 11, 2026
squid-anubis
pushed a commit
that referenced
this pull request
Jul 12, 2026
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_size` is using 64KB default or a larger value). `String::RawSizeMaxXXX()` classifies the increased limit as safe. Also replaced anonymous 32KB limit in HTTP `X-Forwarded-For` request header 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 `String` class is gone from Squid code: * 32KB Ipc::Mem::PageSize(): Strings are not stored in shared memory. * 64KB BodyPipe::MaxCapacity: BodyPipe uses MemBuf, not String. * 64KB Store::SwapMetaFieldValueLengthMax: CheckSwapMetaUrl() and similar Store swap metadata iteration code uses raw memory pointers, not String. UnpackNewSwapMetaVaryHeaders() uses SBuf, not String. * 64KB limit in TeChunkedParser::parse(): We use SBuf, not String for `TeChunkedParser::mimeHeaderBlock_` storage. The hard-coded limit prevents excessive trailer fields accumulation. Other grabMimeBlock() callers already use admin-configurable limits that may exceed 64KB. This is a Measurement Factory project.
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.