-
Notifications
You must be signed in to change notification settings - Fork 129
Fix: Integer Overflow in OptionConverter & Enable >2GB logs on Windows #585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix: Integer Overflow in OptionConverter & Enable >2GB logs on Windows #585
Conversation
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. |
There was a problem hiding this comment.
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" ) ]] |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Summary
I identified a platform-dependent integer overflow in
OptionConverter::toFileSize.The library previously used
longfor file size calculations. On Windows (MSVC),longis 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.hand the implementation inoptionconverter.cppto uselong long(guaranteed 64-bit on all platforms) and leveragedStringHelper::toInt64.Impact