Skip to content

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

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

Use String::RawSizeMaxXXX() to limit String length#2456
somecookie wants to merge 10 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 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.

* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants