Skip to content

Conversation

@CharityKathure
Copy link
Contributor

@CharityKathure CharityKathure commented Jul 1, 2025

This PR addresses an issue where LogMonitor crashes the wrapped process if a log line exceeds 4000 characters.

The previous implementation read directly into a fixed-size buffer and attempted to format/process each chunk as a complete log line. When a line exceeded the buffer size, it resulted in malformed output or unsafe memory access, ultimately crashing the wrapped process.

Changes:

  1. ReadFromPipe refactor:
  • Introduced chBufRem: A buffer to hold incomplete log fragments from a ReadFile call that didn’t end in a newline. These fragments are prepended to the next buffer read to reconstruct complete lines.
  • Output is now accumulated until a complete line ending in \r or \n is detected, ensuring only full lines are processed and written.
  1. Helper Functions (FormatProcessLog, FormatCustomLog and FormatStandardLog now take const std::string instead of char*)

…characters

Signed-off-by: Charity Kathure <ckathure@microsoft.com>
std::string sanitized;
sanitized.reserve(inputLine.size());
for (char c : inputLine) {
sanitized += (c > 0) ? c : '?';
Copy link
Contributor

Choose a reason for hiding this comment

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

we didn't support multi-byte (wide) characters then when we were using char* , now that we moved to std::string, could we consider supporting as the next step, perhaps not on this PR. Might come with some perf hits...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added this to our backlog. Thanks.

@CharityKathure CharityKathure merged commit 09983f6 into main Jul 1, 2025
7 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.

[BUG] 🔥 LogMonitor crashes wrapped process on log line > 4000 characters. This is happening in production ATM

4 participants