Skip to content

Normalize invalid FileAppender buffer sizes#656

Merged
swebb2066 merged 1 commit into
apache:masterfrom
metsw24-max:fileappender-buffersize-validation
May 11, 2026
Merged

Normalize invalid FileAppender buffer sizes#656
swebb2066 merged 1 commit into
apache:masterfrom
metsw24-max:fileappender-buffersize-validation

Conversation

@metsw24-max
Copy link
Copy Markdown
Contributor

Normalize invalid FileAppender buffer size values before storing them in the internal int buffer size field.

FileAppender::_priv->bufferSize is stored as an int, but multiple code paths accepted larger or negative values without validation. On 64-bit systems, oversized values such as 2G could overflow during narrowing conversion and later expand into extremely large size_t values during buffered writer initialization, preventing flush thresholds from triggering and causing unbounded memory growth.

Changes Made

  • Added validation for BUFFERSIZE values parsed via OptionConverter::toFileSize().

  • Invalid values (negative or greater than INT_MAX) now:

    • emit a LogLog::warn
    • fall back to the default 8 KiB buffer size.
  • Added bounds checking in setFileInternal() before narrowing size_t to int.

  • Updated setBufferSize(int) to normalize negative inputs to 0 with a warning.

  • Added <limits> for safe integer boundary checks.

Tests Added

Added regression tests covering:

  • Negative BUFFERSIZE option values.
  • Oversized BUFFERSIZE option values (2G overflow path).
  • Direct negative setBufferSize(int) calls.

Each test verifies that the resulting buffer size remains non-negative and does not pass through signed/unsigned reinterpretation paths.

@swebb2066 swebb2066 merged commit 4ecfbcd into apache:master May 11, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants