Skip to content

Conversation

@OxBat
Copy link

@OxBat OxBat commented Jan 27, 2026

Summary

I identified a platform-dependent integer overflow in OptionConverter::toFileSize.
The library previously used long for file size calculations. On Windows (MSVC), long is strictly 32-bit (LLP64 data model), whereas it is 64-bit on Linux (LP64).

The Issue:
Configuring MaxFileSize="3GB" on Windows triggers a signed integer overflow:
3 * 1024^3 = 3,221,225,472 -> wraps to -1,073,741,824 (negative).
This negative value is passed to RollingFileAppender, causing logic errors (DoS via infinite rotation or rotation failure).

The Fix:
I updated the API signature in optionconverter.h and the implementation in optionconverter.cpp to use long long (guaranteed 64-bit on all platforms) and leveraged StringHelper::toInt64.

Impact

  1. Fixes the Crash/DoS: Prevents negative file size limits.
  2. Enables Feature: Windows users can finally use log files larger than 2GB, ensuring parity with Linux.

OxBat added 2 commits January 27, 2026 18:34
Changed toFileSize signature to return 'long long' instead of 'long'.
On Windows (LLP64), 'long' is 32-bit, causing overflow for sizes >= 2GB.
Using 'long long' guarantees 64-bit width, preventing negative file sizes
and enabling support for large log files.
Restored original 'long toFileSize' signature to preserve binary compatibility.
Added new 'toFileSize64' method for 64-bit support.
Old method now wraps the new one with safety clamping to prevent overflow.
and gigabytes. For example, the value "10KB" will be interpreted as 10240.
*/
/**
* @deprecated Use toFileSize64 instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

this should use the newer [[deprecated]] annotation like is used in other places(example:

[[ deprecated( "Use getName() instead" ) ]]
)

Copy link
Author

Choose a reason for hiding this comment

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

Done.

* The numeric equivalent of \c value if it is not empty, otherwise \c defaultValue.
* Supports 64-bit values for file sizes > 2GB.
*/
static long long toFileSize64(const LogString& value, long long defaultValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

@swebb2066 any thoughts on long long vs. int64_t? The latter is used in a few parts of the API, but they should both be equivalent.

Copy link
Author

Choose a reason for hiding this comment

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

I went with long long just to be safe on Windows (LLP64), but I see int64_t is used elsewhere. I can switch to that for consistency if you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

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

any thoughts on long long vs. int64_t

I prefer int64_t for its explicit size and the single word

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.

3 participants