OxBat opened a new pull request, #586:
URL: https://github.com/apache/logging-log4cxx/pull/586

   ### Summary
   I identified a critical algorithmic defect in `AsyncAppender::setBufferSize`.
   The appender uses a Ring Buffer with modulo arithmetic (`index = counter % 
size`).
   When the buffer size changes, the modulus changes, invalidating the mapping 
of existing data.
   
   **The Crash:**
   If the buffer contains wrapped data, the reader calculates indices based on 
the *new* size. These indices point to slots that are logically empty 
(containing `nullptr` from `std::vector::resize`). Dereferencing them causes a 
SEGFAULT.
   
   ### Technical Analysis
   The `append` method uses a lock-free write path relying on `eventCount`.
   `setBufferSize` simply called `resize()`, which breaks the `index = count % 
size` invariant for existing data.
   
   ### Remediation
   The patch implements a "Drain and Re-align" strategy:
   1. Creates a new aligned buffer.
   2. Copies pending committed events linearly (starting at index 0).
   3. Resets atomic counters (`dispatchedCount`, `commitCount`, `eventCount`) 
to match the new linear layout.
   
   Note: This fix assumes the caller pauses logging before resizing 
(Quiescence), which is required anyway as `append()` does not hold the mutex 
during writes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to