Skip to content

Use String::RawSizeMaxXXX() to limit String length#2456

Closed
somecookie wants to merge 13 commits into
squid-cache:masterfrom
measurement-factory:OSD-7-use-RawSizeMaxXXX
Closed

Use String::RawSizeMaxXXX() to limit String length#2456
somecookie wants to merge 13 commits into
squid-cache:masterfrom
measurement-factory:OSD-7-use-RawSizeMaxXXX

Conversation

@somecookie

Copy link
Copy Markdown
Contributor

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.

rousskov
rousskov previously approved these changes Jul 7, 2026

@rousskov rousskov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this cleanup and a careful evaluation of Squid code to find all String::RawSizeMaxXXX() candidates.

Comment thread src/http/one/RequestParser.cc Outdated
* 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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@rousskov rousskov added M-cleared-for-merge https://github.com/measurement-factory/anubis#pull-request-labels S-could-use-an-approval An approval may speed this PR merger (but is not required) labels Jul 7, 2026
Comment thread src/servers/FtpServer.cc Outdated
Comment thread src/http/one/RequestParser.cc Outdated
Co-authored-by: Francesco Chemolli <5175948+kinkie@users.noreply.github.com>
rousskov
rousskov previously approved these changes Jul 9, 2026
Comment thread src/servers/FtpServer.cc Outdated
@rousskov

rousskov commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@somecookie, applying those out-of-scope changes broke formatting. Please reformat (which means more unnecessary line changes; sigh).

@yadij yadij added the S-waiting-for-author author action is expected (and usually required) label Jul 10, 2026
@rousskov rousskov removed the S-waiting-for-author author action is expected (and usually required) label Jul 10, 2026
@squid-anubis squid-anubis added the M-failed-other https://github.com/measurement-factory/anubis#pull-request-labels label 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.
@squid-anubis squid-anubis added M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels and removed M-failed-other https://github.com/measurement-factory/anubis#pull-request-labels labels Jul 12, 2026
@rousskov rousskov removed the S-could-use-an-approval An approval may speed this PR merger (but is not required) label Jul 12, 2026
@squid-anubis squid-anubis added M-merged https://github.com/measurement-factory/anubis#pull-request-labels and removed M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels M-cleared-for-merge https://github.com/measurement-factory/anubis#pull-request-labels labels Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

M-merged https://github.com/measurement-factory/anubis#pull-request-labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants